TypeScript Best Practices (2026): Strict Types & Agent Skills
Strict TypeScript prevents entire classes of runtime bugs when coding agents avoid any, model states with discriminated unions, and parse unknown inputs at boundaries. Use the checklist below or inspect these audited TypeScript SKILL.md repos on GitHub.
Updated: 2026-11-21 · Works with Claude Code, Cursor, Codex, and Windsurf
Core TypeScript Best Practices
Turn on strict, noUncheckedIndexedAccess, and verbatimModuleSyntax
Lock strict compiler flags in tsconfig.json so missing null checks, unsafe array indexing, and broken ESM imports fail at compile time.
"strict": false, "skipLibCheck": true"strict": true, "noUncheckedIndexedAccess": true, "exactOptionalPropertyTypes": trueUse unknown at untrusted boundaries and validate with a schema
Treat JSON payloads, env vars, and webhook bodies as unknown, then parse with Zod or Valibot before passing typed objects deeper into your app.
const body: any = await req.json();const body = CreateOrderSchema.parse(await req.json());Model state machines with discriminated unions instead of boolean flags
Replace overlapping isLoading/isError/data booleans with tagged unions so TypeScript forces exhaustive handling of every branch.
type State = { loading: boolean; error?: string; data?: User };type State = { status: "loading" } | { status: "error"; message: string } | { status: "ready"; user: User };Prefer satisfies over type assertions (as)
Use satisfies to validate object literals against a shape while preserving narrow literal inference instead of silencing the compiler with as.
const routes = { home: "/", pricing: "/pricing" } as Record<string, string>;const routes = { home: "/", pricing: "/pricing" } satisfies Record<string, `/${string}`>;Use type-only imports and narrow return contracts on exported APIs
Declare explicit return types on public module functions and import types with import type to prevent accidental runtime circular dependencies.
import { User } from "./types"; export function format(u) { ... }import type { User } from "./types"; export function format(u: User): string { ... }Verify every edit with tsc --noEmit before finishing a task
Run full project type-checking and linting after agent edits so type errors in sibling files get caught before commit.
npm run dev (visual check only)pnpm tsc --noEmit && pnpm testOpen-Source TypeScript Agent Skills (5)
| Skill & Publisher | Stars | Install |
|---|---|---|
Engineering skill from Matt Pocock guiding coding agents to design cohesive TypeScript modules, narrow interfaces, and testable seams before writing implementation code. | ★ 329,578 | |
Teaches coding agents to encode domain rules, transitions, and illegal-state guards directly in the TypeScript type system before implementing handlers or UI. | ★ 329,578 | |
MIT-licensed TypeScript skill from Node.js TSC member Matteo Collina focused on generic constraints, type guards, utility types, and strict runtime-to-type narrowing. | ★ 1,979 | |
Concise MIT-licensed TypeScript style guide skill covering discriminated unions, naming, source organization, function signatures, and strict maintainability rules. | ★ 786 | |
Official MIT-licensed skill from Microsoft guiding coding agents through strict TypeScript configuration, incremental strictness adoption, and zero-regression compiler upgrades. | ★ 4 |
Building with TypeScript and an AI coding agent?
Builderthread pairs verified skills with a private GitHub starter repo, living PRD, and MCP task board for Claude Code, Cursor, and Codex.
Questions about TypeScript Best Practices & Skills
What are the highest-impact TypeScript best practices for AI coding agents?
Enable strict and noUncheckedIndexedAccess in tsconfig.json, forbid any in favor of unknown plus schema validation, model async and domain state as discriminated unions, avoid as type casts, and run tsc --noEmit after every edit.
Which open-source TypeScript skills work with Claude Code and Cursor?
Official and high-reputation options include microsoft/typescript-skills (typescript-strict), mkosir/typescript-style-guide, mcollina/skills (typescript-magician), and mattpocock/skills (codebase-design and domain-modeling).
How do TypeScript skills prevent agents from using any or @ts-ignore?
The SKILL.md instructions set explicit bans on any, @ts-ignore, and unsafe as assertions, steering the model to write type guards, generic constraints, and satisfies checks instead.
Related Skill Guides
Strict TypeScript from commit one
Pair strict TypeScript rules with a working starter repo
Builderthread generates strict TypeScript repos for Next.js SaaS, Hono APIs, and WXT Chrome extensions, backed by a living PRD, curated skills, and MCP tasks checked with tsc --noEmit.