| name | check |
| description | /ts-patterns:check — Enforce TypeScript best practices inline while writing or editing .ts/.tsx files: no any, explicit return types, readonly by default, async/await only.
Trigger automatically when: - Writing new TypeScript files or modules - Reviewing or editing existing .ts / .tsx files - Converting JavaScript to TypeScript - Asked to refactor or improve TypeScript code quality - Implementing features in a TypeScript project
Natural language triggers: "write this in TypeScript", "review my TypeScript", "refactor this TS file", "enforce patterns", "check type safety", "improve types".
This skill applies inline. For full PR reviews or large multi-file refactors, the ts-patterns agent is available for deeper delegated work.
|
TypeScript Pattern Enforcement
Apply these principles to every TypeScript file you write or edit.
Core Rules
- No
any — use unknown and narrow, or define a precise type. Justify every as cast with a comment.
- Explicit return types — annotate public functions; let inference handle private/internal one-liners only.
- Prefer
interface for extendable shapes; type for unions, intersections, and mapped/conditional types.
readonly by default — mark properties and arrays immutable unless mutation is required.
async/await only — no raw .then() chains, no callbacks. Return Promise<T> explicitly.
- Typed errors — custom classes extending
Error, or discriminated-union result types. Never silently swallow.
- Generics with constraints —
<TEntity extends BaseEntity> not just <T>. Use descriptive names.
- Composition over inheritance — classes only when necessary; prefer plain functions and utility types.
File Layout
// 1. Types and interfaces (exported first)
// 2. Constants
// 3. Implementation (private helpers, then public exports)
// 4. Barrel re-exports in index.ts
Utility Types to Reach For
Partial<T> · Required<T> · Readonly<T> · Pick<T, K> · Omit<T, K> · ReturnType<F> · Parameters<F> · Record<K, V> · discriminated unions with never for exhaustive checks.
Anti-Patterns to Flag
any / unguarded as casts
- Mutating function parameters
- Deeply nested
.then().catch() chains
- Magic strings/numbers (extract to
const or enum)
- Missing error handling in
async functions
- Classes with no private state (use plain functions instead)
@ts-ignore without a follow-up TODO
Review Checklist
Before finalising: