Instruction file imported from Wamocon/ghostaccounts (
.github/instructions/typescript.instructions.md). Copyright stays with the author.
TypeScript Best Practices
Type Safety
- Enable
strictmode intsconfig.json(already configured). - Use
import type { ... }for type-only imports — keeps runtime bundles clean. - Prefer
interfacefor object shapes; usetypefor unions, intersections, and mapped types. - Never use
any. Useunknownwhen the type is genuinely unknown, then narrow it.
Patterns
- Use discriminated unions for state management and API responses.
- Prefer
as constfor literal types and const assertions. - Use
satisfiesoperator to validate types without widening. - Extract shared types to
src/types/— keep them co-located if only used in one module.
Naming Conventions
- Interfaces/Types: PascalCase (
UserProfile,ApiResponse). - Variables/Functions: camelCase (
getUserById,isLoading). - Constants: UPPER_SNAKE_CASE for true constants, camelCase for computed values.
- Components: PascalCase file names matching the export (
UserCard.tsx).
Enums
- Avoid
enum— useas constobjects or string literal union types instead.