typescript
SKILL.md
TypeScript
Strict, type-safe TypeScript for any codebase — frontend, backend, libraries, CLIs.
When to activate
- Writing or modifying
.tsor.tsxfiles - Reviewing TypeScript code for quality
- Refactoring JavaScript to TypeScript
- Debugging type errors or inference failures
- Setting up or auditing
tsconfig.json
Core rules
NEVER
- Use
any— useunknownand narrow with type guards - Use
astype assertions without runtime validation - Use
@ts-ignore— use@ts-expect-errorwith a reason comment - Use numeric enums — use
as constobjects or string unions - Mutate function arguments — return new objects/arrays
- Throw non-Error objects — always
throw new Error()or a custom error class - Skip
strictNullChecks— handlenull/undefinedexplicitly - Use barrel exports (
export *) in performance-sensitive code - Import types as values — use
import typefor type-only imports
ALWAYS
- Enable
"strict": trueintsconfig.json - Annotate function parameters and return types
- Let TypeScript infer local variables — don't over-annotate
- Use discriminated unions with a
typeorkindfield for state - Use
readonlyfor data that should not be mutated - Use
as constfor literal objects and arrays - Prefer
interfacefor object shapes that may be extended;typefor unions, intersections, utilities - Handle errors with typed catch blocks — check
instanceof Error - Use
Promise.allfor independent async operations - Write exhaustive
switchstatements withneverdefault
Decision tree
Choosing between type and interface
Need union, intersection, or utility? → type
Need declaration merging or extends? → interface
Data shape for objects? → interface (default)
Everything else? → type
Choosing error handling strategy
External input (API, user, file)? → Validate at boundary with type guard or schema (Zod)
Internal function failure? → Return Result<T, E> discriminated union
Unrecoverable state? → throw new CustomError()
Choosing between generics and concrete types
Used with multiple types? → Generic with constraints
Used with one type? → Concrete type (don't over-abstract)
Generic parameter unused in body? → Remove it — it's unnecessary
Reference routing
Load only the files relevant to the current task.
| File | When to read |
|---|---|
references/anti-patterns.md |
When writing new code, reviewing code, or refactoring. Contains the full catalog of mistakes with fixes. |
references/type-system.md |
When working with advanced types: generics, conditionals, mapped types, template literals, branded types, recursive types. |
references/patterns.md |
When implementing common TypeScript patterns: Result types, type guards, discriminated unions, builder pattern, const assertions. |
references/strict-config.md |
When setting up or auditing tsconfig.json, diagnosing type performance, or configuring module resolution. |
Weekly Installs
1
Repository
yigitkonur/skil…gitkonurFirst Seen
6 days ago
Security Audits
Installed on
mcpjam1
github-copilot1
junie1
windsurf1
zencoder1
crush1