TypeScript essentials (what you need for this stack)
TypeScript helps us express data shapes, prevent whole classes of bugs, and make refactors safe. It does not replace runtime validation (we use Zod for that).
Use these sources (in order)
- TypeScript Handbook: https://www.typescriptlang.org/docs/handbook/intro.html
- Everyday Types: https://www.typescriptlang.org/docs/handbook/2/everyday-types.html
- Narrowing: https://www.typescriptlang.org/docs/handbook/2/narrowing.html
- More on Functions: https://www.typescriptlang.org/docs/handbook/2/functions.html
- Object Types: https://www.typescriptlang.org/docs/handbook/2/objects.html
- Generics: https://www.typescriptlang.org/docs/handbook/2/generics.html
What “good” looks like
- Use types to model domain data (not just “make the compiler happy”).
- Prefer
unknownoveranyat boundaries. - Use narrowing (
typeof,in, predicates) to make unsafe data safe. - Avoid over-abstracting with generics; keep it readable.
Where it shows up in our stack
- React: props and component state
- Zod:
z.infer<typeof schema>for shared types - tRPC: end-to-end typing for procedure inputs/outputs
- Tests: typed factories and helpers
Exercises (planned)
- Refactor a JS utility to typed TS + Vitest tests.
- Model procedure inputs/outputs and remove
anyfrom a feature.
Last updated on