# TypeScript Best Practices (2026): Strict Types & Agent Skills

- **Topic**: TypeScript
- **Canonical URL**: https://builderthread.dev/skill/for/typescript
- **Parent Hub**: https://builderthread.dev/skill.md
- **Last Verified**: 2026-11-21

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.

---

## Core TypeScript Best Practices Checklist

### 1. 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`

### 2. 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());`

### 3. 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 };`

### 4. 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}`>;`

### 5. 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 { ... }`

### 6. 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`

---

## Verified Skills for TypeScript (5)

| Skill | Publisher | License | Stars | GitHub Source | Install Command |
|---|---|---|---|---|---|
| [codebase-design](https://builderthread.dev/skill/mattpocock/skills/codebase-design.md) | Matt Pocock | MIT | 329,578 | [GitHub](https://github.com/mattpocock/skills/tree/main/skills/engineering/codebase-design) | `npx skills add mattpocock/skills --skill codebase-design` |
| [domain-modeling](https://builderthread.dev/skill/mattpocock/skills/domain-modeling.md) | Matt Pocock | MIT | 329,578 | [GitHub](https://github.com/mattpocock/skills/tree/main/skills/engineering/domain-modeling) | `npx skills add mattpocock/skills --skill domain-modeling` |
| [typescript-magician](https://builderthread.dev/skill/mcollina/skills/typescript-magician.md) | Matteo Collina | MIT | 1,979 | [GitHub](https://github.com/mcollina/skills/tree/main/skills/typescript-magician) | `npx skills add mcollina/skills --skill typescript-magician` |
| [typescript-style-guide](https://builderthread.dev/skill/mkosir/typescript-style-guide/typescript-style-guide.md) | Milos Kosir | MIT | 786 | [GitHub](https://github.com/mkosir/typescript-style-guide/tree/main/skills/typescript-style-guide) | `npx skills add mkosir/typescript-style-guide --skill typescript-style-guide` |
| [typescript-strict](https://builderthread.dev/skill/microsoft/typescript-skills/typescript-strict.md) | Microsoft | MIT | 4 | [GitHub](https://github.com/microsoft/typescript-skills/tree/main/plugins/typescript/skills/typescript-strict) | `npx skills add microsoft/typescript-skills --skill typescript-strict` |

---

## Frequently Asked Questions

### 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

- [Next.js](https://builderthread.dev/skill/for/nextjs.md) ([Web](https://builderthread.dev/skill/for/nextjs)): Next.js 16 & React 19 Best Practices (2026): Official Agent Skills
- [Hono API](https://builderthread.dev/skill/for/hono.md) ([Web](https://builderthread.dev/skill/for/hono)): Hono API Best Practices (2026): Typed Routes, RPC & Agent Skills
- [Chrome Extensions](https://builderthread.dev/skill/for/chrome-extension.md) ([Web](https://builderthread.dev/skill/for/chrome-extension)): Chrome Extension Manifest V3 Best Practices (2026) & Agent Skills
- [Testing](https://builderthread.dev/skill/for/testing.md) ([Web](https://builderthread.dev/skill/for/testing)): Best Agent Skills for Automated Testing & Playwright CLI

---

## Ship With a Private Starter Repo, Living PRD & MCP Tasks

Builderthread generates strict TypeScript starter repos for Next.js SaaS, Hono APIs, and WXT Chrome extensions, pre-wired with a living PRD, curated skills, and MCP build tasks.

- Supported languages: Rust, TypeScript, React Native (Expo), Python
- Starter stacks: Next.js SaaS, Hono API, FastAPI AI, Expo mobile, Tauri Rust desktop, WXT Chrome extension
- Start now: https://builderthread.dev/auth/signup
