TypeScript
Strict, idiomatic TypeScript — tsconfig hardening, narrowing and discriminated unions, runtime validation at boundaries, generics, module settings, type-level pitfalls and fast type-check workflows.
What it does
Strict, idiomatic TypeScript — tsconfig hardening, narrowing and discriminated unions, runtime validation at boundaries, generics, module settings, type-level pitfalls and fast type-check workflows.
- Category
- weblanguagetyping
- Platforms
- webbackend
- Frameworks and tools
- typescript
- Capabilities
- code-generationreviewrefactoring
Example tasks
- “Migrate a loosely typed module to strict mode and remove the any types.”
- “Model API responses with discriminated unions and validate them at runtime.”
- “Fix a confusing generic constraint error in a utility function.”
Works with
Permissions summary
Files
Reads files only
Shell
No shell commands
Network
No network
Permissions are declared in the component manifest and compiled into each client's tool list. Components are built for least privilege.
Supported environments
| Client | Support | Installed as |
|---|---|---|
| Claude Code | Native | .claude/skills/<id>/SKILL.md |
| OpenAI Codex | Adapter | .codex/skills/<id>/SKILL.md |
| Cursor | Adapter | .cursor/rules/<id>.mdc |
| VS Code (Copilot) | Adapter | .github/instructions/<id>.instructions.md |
| Generic markdown | Adapter | docs/forgekit/skills/<id>.md |
Claude Code is the native reference. Other clients use adapters, so behaviour is close but not identical. See the compatibility matrix.
Included in packs
Full skill (free preview)
This is a free component, so its complete content is public. It is exactly what gets installed (before client-specific formatting).
TypeScript
Write types that make invalid states unrepresentable and that tell the truth at runtime boundaries. Read the repo's tsconfig*.json, lint config and existing patterns first; match them. Check the TypeScript version in package.json before using newer syntax and verify option names against the official tsconfig reference.
1. Compiler configuration
| Option | Recommendation |
|---|---|
strict: true | Always for new code (enables strictNullChecks, noImplicitAny, strictFunctionTypes, ...) |
noUncheckedIndexedAccess | On; array/record indexing returns T | undefined |
exactOptionalPropertyTypes | Consider on for new code; stricter about undefined vs missing |
noImplicitOverride, noFallthroughCasesInSwitch | On |
verbatimModuleSyntax | On; forces explicit import type and predictable emit |
isolatedModules | On when using a bundler/transpiler per file (Vite, esbuild, SWC) |
moduleResolution | bundler for bundled apps, NodeNext (with module: NodeNext) for Node ESM/CJS packages |
skipLibCheck | Acceptable for speed; do not use it to hide errors in your own .d.ts |
noEmit | On for apps where a bundler emits; run tsc --noEmit in CI |
Migrating a lax codebase: enable strict per package or use // @ts-expect-error with a reason on remaining violations, tracked by count; ratchet down. Prefer @ts-expect-error over @ts-ignore so stale suppressions fail.
2. Modeling rules
- Avoid
any. Useunknownfor untrusted values and narrow; use generics when the type flows through. - Model variants as discriminated unions with a literal tag and exhaustive switch:
type Result<T> = { ok: true; value: T } | { ok: false; error: string }; function assertNever(x: never): never { throw new Error(`Unhandled: ${JSON.stringify(x)}`); } - Prefer
typealiases for unions/mapped types andinterfacefor extendable object contracts; stay consistent with the repo. - Use
as constandsatisfiesto keep literal types while checking shape:const routes = { home: "/" } as const satisfies Record<string, string>. - Prefer string-literal unions over
enum(oras constobjects); enums add runtime code and quirks. - Use branded types for ids that must not mix:
type UserId = string & { readonly __brand: "UserId" }, created in one validated constructor. - Make illegal states unrepresentable: replace
{ loading: boolean; data?: T; error?: E }with a tagged union. - Use
readonlyandReadonlyArrayfor inputs you do not mutate.
3. Narrowing and assertions
- Use user-defined guards (
x is Foo),in,typeof,instanceof, and equality narrowing. Prefer narrowing overas. asand!are escape hatches: allow them only with an adjacent comment explaining the invariant. Neveras unknown as Tto silence an error.satisfieschecks without widening; use it instead of annotating when you want the inferred literal type.
4. Runtime boundaries
Types vanish at runtime. Validate all external data (HTTP bodies, query strings, env vars, JSON files, localStorage, message payloads) with a schema library such as Zod, Valibot or ArkType, and derive the static type from the schema (z.infer<typeof Schema>) so there is one source of truth. Parse once at the edge, pass typed values inward. JSON.parse returns any; never trust it directly. Env vars are string | undefined; parse them into a typed config object at startup.
5. Generics and utility types
- Constrain generics (
<T extends { id: string }>) and let inference work; do not pass explicit type arguments unless needed. - Use built-ins:
Pick,Omit,Partial,Required,Record,ReturnType,Parameters,Awaited,NonNullable,Extract,Exclude. - Keep type-level cleverness proportional: if a conditional type needs a comment longer than the function, simplify or use overloads.
- Overloads: order most specific first; provide an implementation signature that is not itself callable.
6. Workflow
- Fast feedback:
tsc --noEmit -p tsconfig.json(add--incremental); usetsc -bfor project references in monorepos. - Use typed lint rules from
typescript-eslint(no-floating-promises,no-misused-promises,consistent-type-imports,no-unnecessary-type-assertion). - Export types from modules explicitly; avoid deep imports across package boundaries.
- Fix errors at the source type rather than adding casts at each use.
Common mistakes
Object.keys(obj)typed asstring[]; do not cast to(keyof T)[]without justification.- Optional property vs
T | undefined; they differ underexactOptionalPropertyTypes. - Async functions typed as returning
Tinstead ofPromise<T>, or unhandled floating promises. - Using
Function,object,{}as types; use specific signatures orRecord<string, unknown>. - Trusting API types generated once and never regenerated.
Version and changelog
Latest version 1.0.0. Requires DevBuildKit CLI 1.0.0 or newer.
Changelog — TypeScript
1.0.0
- Initial release.