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

Quick Reference Checklist

Core TypeScript Best Practices

01

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.

Avoid:"strict": false, "skipLibCheck": true
Prefer:"strict": true, "noUncheckedIndexedAccess": true, "exactOptionalPropertyTypes": true
02

Use 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.

Avoid:const body: any = await req.json();
Prefer:const body = CreateOrderSchema.parse(await req.json());
03

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.

Avoid:type State = { loading: boolean; error?: string; data?: User };
Prefer:type State = { status: "loading" } | { status: "error"; message: string } | { status: "ready"; user: User };
04

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.

Avoid:const routes = { home: "/", pricing: "/pricing" } as Record<string, string>;
Prefer:const routes = { home: "/", pricing: "/pricing" } satisfies Record<string, `/${string}`>;
05

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.

Avoid:import { User } from "./types"; export function format(u) { ... }
Prefer:import type { User } from "./types"; export function format(u: User): string { ... }
06

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.

Avoid:npm run dev (visual check only)
Prefer:pnpm tsc --noEmit && pnpm test

Open-Source TypeScript Agent Skills (5)

Showing 5 of 5 verified skillsStandard: SKILL.md specification
Skill & PublisherStarsInstall
by Matt Pocock•typescript

Engineering skill from Matt Pocock guiding coding agents to design cohesive TypeScript modules, narrow interfaces, and testable seams before writing implementation code.

★ 329,578
by Matt Pocock•typescript

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
by Matteo Collina•typescript

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
by Milos Kosir•typescript

Concise MIT-licensed TypeScript style guide skill covering discriminated unions, naming, source organization, function signatures, and strict maintainability rules.

★ 786
by Microsoft•typescript

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.

Frequently Asked Questions

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.

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.

Six private starter repos, one MCP workflow
Next.js SaaS
Hono API
FastAPI AI
Expo mobile
Tauri Rust
Chrome extension
100% code ownership in your GitHubLiving PRD + MCP task boardStarts at $29 one-time
Start my SaaS blueprintTry free architecture preview

Free preview needs no signup or card