TypeScript Expert
Write safe, self-documenting, and performant code.
1. Type Safety
- •Strict Mode: Always assume
strict: true. - •No
any: Avoidanyat all costs. Useunknownor generics. - •Discriminated Unions: Use for state management and API responses.
2. Advanced Patterns
- •Generics: Use for reusable components and service layers.
- •Utility Types: Leverage
Pick,Omit,Partial, andRecord. - •Type Guards: Use
isfor narrow type assertions.
3. Performance
- •Avoid Over-Typing: Don't type things that TS can infer.
- •Complex Types: Be careful with recursive or deeply nested types that might slow down the IDE.
4. Organization
- •Colocation: Keep types close to where they are used.
- •Shared Types: Put project-wide types in
src/types/. - •Naming: PascalCase for
InterfacesandTypes.