| name | ts-coding-standards |
| description | Use when writing, reviewing, or refactoring TypeScript code. Provides type safety patterns, error handling, project layout, and async programming guidelines. |
| allowed-tools | Read, Grep, Glob |
TypeScript Coding Standards
This skill provides modern TypeScript coding guidelines and best practices for this project.
When to Apply
Apply these standards when:
- Writing new TypeScript code
- Reviewing or refactoring existing TypeScript code
- Designing module APIs and interfaces
- Implementing error handling strategies
Core Principles
- Type Safety Over Convenience - Never sacrifice type safety for shorter code
- Explicit Over Implicit - Make types and intentions clear
- Simple Over Clever - Prefer readable code over clever abstractions
- Fail Fast - Catch errors at compile time, not runtime
Quick Reference
Must-Use Patterns
| Pattern | Use Case |
|---|
| Discriminated Unions | State machines, API responses, Result types |
| Branded Types | IDs, emails, validated strings |
readonly | Data that should not mutate |
unknown in catch | Safe error handling |
| Explicit undefined checks | Array/object indexed access |
Must-Avoid Anti-Patterns
| Anti-Pattern | Alternative |
|---|
any type | unknown with type guards |
| Throwing exceptions for control flow | Result type pattern |
| Optional chaining without null check | Explicit narrowing |
| Deep folder nesting (>3 levels) | Flat, feature-based structure |
Implicit undefined in optional props | Explicit T | undefined |
Detailed Guidelines
For comprehensive guidance, see:
tsconfig.json Strict Mode
This project uses maximum TypeScript strictness. Ensure your code compiles with:
{
"compilerOptions": {
"strict": true,
"noUncheckedIndexedAccess": true,
"exactOptionalPropertyTypes": true,
"noPropertyAccessFromIndexSignature": true,
"noFallthroughCasesInSwitch": true,
"noImplicitOverride": true,
"noImplicitReturns": true,
"noUnusedLocals": true,
"noUnusedParameters": true
}
}
References