Goal: catch errors at compile time with types that aid, not obstruct.
Use for:
- new TypeScript code or migrating from JavaScript
- reviewing type usage, strictness, and module structure
- removing
any, casts, and unsafe escape hatches
Workflow:
- Enable strict mode and treat its warnings as errors.
- Type module and function boundaries; let locals infer.
- Model data with unions and interfaces, not loose objects.
- Narrow with type guards before using union members.
- Replace
anywithunknownand narrow deliberately. - Verify with tsc, eslint, and tests.
Idioms:
satisfiesto validate without widening- discriminated unions for variant data
- readonly and const assertions for immutability
- utility types (Pick, Omit, Partial, Record)
Rules:
- strict mode on; no implicit any
- avoid type assertions; prove the type instead
- do not export inferred wide types from APIs
- a type that lies is worse than no type