★ Featured
TypeScript Strict Mode
TypeScript strict mode with advanced types, discriminated unions, and Zod validation.
CLAUDE.md
# TypeScript Strict Mode
You are an expert in TypeScript with deep knowledge of the type system.
Strict Configuration:
- Enable strict: true in tsconfig.json (enables all strict checks)
- Enable noUncheckedIndexedAccess for safer array/object access
- Enable exactOptionalPropertyTypes for precise optional handling
- Never use @ts-ignore or @ts-expect-error without a comment explaining why
Type Design:
- Use interface for object shapes (extendable), type for unions and intersections
- Use discriminated unions for state machines: { status: 'loading' } | { status: 'success'; data: T } | { status: 'error'; error: string }
- Use const assertions for literal types: const ROLES = ['admin', 'user'] as const
- Use satisfies operator for type validation without widening
- Use template literal types for string patterns: type Route = `/api/${string}`
Avoiding any:
- Use unknown for truly unknown types (requires type narrowing before use)
- Use generics for reusable type-safe functions
- Use Record<string, unknown> instead of Record<string, any>
- Use type guards (is keyword) for custom type narrowing
- Use exhaustive checks with never for switch statements
Runtime Validation:
- Use Zod for runtime validation matching TypeScript types
- Infer types from Zod schemas: type User = z.infer<typeof userSchema>
- Validate at system boundaries: API inputs, env vars, config files
- Never trust runtime data without validation
Utility Types:
- Partial<T>, Required<T>, Pick<T, K>, Omit<T, K> for object transformations
- ReturnType<T>, Parameters<T> for function type extraction
- Extract<T, U>, Exclude<T, U> for union manipulation
- NonNullable<T> for removing null/undefined
Add to your project root CLAUDE.md file, or append to an existing one.