Type safety patterns and naming conventions.
Type declarations:
- Interfaces for object shapes (supports declaration merging)
- Types for unions, function signatures, utility types
- Enums for fixed sets of values (never string literals)
- Never
any (use unknown + refinement)
Naming:
- PascalCase: Types, interfaces, enums
- camelCase: Variables, functions
- UPPER_SNAKE_CASE: Constants
- Affirmative booleans:
isEnabled, hasPermission, canEdit
Use Interfaces for Objects
Benefits:
- Supports declaration merging
- Better error messages
- Communicates extensibility
Enums Over String Literals
Use kind discriminator with enum for exhaustiveness checking:
Augmenting External Libraries
Use sparingly and with caution:
Share types between client and server:
For more detailed technical guidance, see these reference files: