Chapter 8 · Practice 1 of 4
Use TypeScript in strict mode and type your props
From Project hygiene
Why it matters
TypeScript catches wrong props, missing cases and null values before they reach users, and it makes refactors safe.
- Turn on
strictintsconfig.jsonfrom the start; enabling it later on a large codebase is painful. - Type props with a plain type or interface.
- Extend native props with
React.ComponentProps<'button'>instead of retyping them.
Avoid any: it silently turns off type checking. When you really do not know the shape, for example for data from an API, use unknown and narrow it before use.
Avoid
anyin props or API responses- Turning off strict checks to silence errors