author: dotagents name: typescript-types description: Deep TypeScript typing for discriminated unions, exhaustive handling, generics, satisfies, branding, and fixing tsc output without any or silent unknown on public APIs. Use when resolving complex type errors or designing type-heavy APIs. Pairs with general-typescript (no any; unknown only with explicit user approval). Triggers on generics, union, narrowing, exhaustive, satisfies, inference.
TypeScript types
Use this skill when general-typescript is not enough: complex generics, discriminated unions, inference breaks, tsc errors that need structure changes, or public type-heavy APIs.
When to use
tscreports errors involving generics, indexed access, mapped types, or conditional types.- New variants of a union should force compile-time updates (exhaustive
switchorif/elsechains). - You need branded or opaque nominal-style types on top of structural typing.
anyorunknownappears at a boundary and needs a narrowing strategy.
Practices
- Discriminated unions: a shared literal discriminant (
kind,type,tag) on every variant; narrow withswitchandassertNever-style exhaustiveness. See reference-unions-exhaustive.md. - Generics: constrain with
extends; avoid unbounded type parameters on public APIs when a minimal constraint exists; prefer inference from values before adding explicit type arguments. See reference-generics-inference.md. satisfies: preserve literal types while checking assignability to a wider shape; use whenas constalone is insufficient.- Type guards: user-defined predicates
x is Fooonly when the runtime check matches the type claim. - Avoid widening fixes: prefer
satisfies, helper generics, or splitting overloads overas any, rawany, or@ts-expect-errorwithout justification.unknownon an export requires explicit user approval per the TypeScript bundle spec—do not introduce it silently.
Reference index
| Topic | File |
|---|---|
| Unions, narrowing, exhaustive checks | reference-unions-exhaustive.md |
| Generics, inference, constraints | reference-generics-inference.md |
External anchors
Delegation
If the change is mostly Bun, eslint, test runner, or import graph hygiene, use general-typescript instead; return here for type-level design and tsc fixes.