TypeScript Pro
Advanced TypeScript 5.x type systems and end-to-end type safety.
When to use
Advanced generics, conditional/mapped types, branded types, discriminated unions, monorepo project references, tRPC full-stack type safety, type guards.
Core workflow
- Analyze — tsconfig, type coverage, build perf.
- Design type-first APIs — branded types, generics, utility types.
- Implement — type guards, discriminated unions, conditional types;
tsc --noEmit to catch errors.
- Optimize build — project references, incremental compilation, tree shaking; re-run
tsc --noEmit.
- Test types — verify with
type-coverage; all public APIs have explicit return types. Iterate until zero errors.
Key patterns
// Branded types — prevent id mix-ups at compile time
type Brand<T, B extends string> = T & { readonly __brand: B };
type UserId = Brand<string, "UserId">;
const toUserId = (id: string): UserId => id as UserId;
// Discriminated union + exhaustive guard
type RequestState =
| { status: "loading" }
| { status: "success"; data: string[] }
| { status: "error"; error: Error };
function render(s: RequestState): string {
switch (s.status) {
case "loading": return "Loading…";
case "success": return s.data.join(", ");
case "error": return s.error.message;
default: { const _x: never = s; throw new Error(_x); }
}
}
// tsconfig.json essentials
{ "compilerOptions": {
"strict": true, "noUncheckedIndexedAccess": true,
"exactOptionalPropertyTypes": true, "isolatedModules": true,
"declaration": true, "incremental": true } }
Constraints
MUST: strict mode + all flags; type-first API design; branded types for domain modeling; satisfies for validation; discriminated unions for state machines; generate declaration files for libraries; optimize for inference.
MUST NOT: any without justification; skip type coverage on public APIs; mix type-only/value imports; disable strict null checks; needless as assertions; use enums (prefer const objects as const).
Output
- Type definitions. 2. Implementation with type guards. 3. tsconfig if needed. 4. Brief note on type design.
Knowledge
TypeScript 5.x, generics, conditional/mapped/template-literal types, discriminated unions, type guards, branded types, tRPC, project references, declaration files, const assertions, satisfies.
1---2name: typescript-pro3description: "Use when building TypeScript applications needing advanced generics, conditional or mapped types, discriminated unions, branded types, monorepo setup, or full-stack type safety with tRPC. Triggers: TypeScript, generics, type safety, conditional types, mapped types, tRPC, tsconfig, type guards, discriminated unions, satisfies."4version: 1.0.05license: MIT6tags: [typescript, generics, type-safety, trpc, type-guards, discriminated-unions, tsconfig, satisfies]7source: https://github.com/jeffallan/claude-skills/tree/main/skills/typescript-pro8derived_from: awesomeclaude9metadata:10 source: https://skillmd.com/skills/aashutosh396/typescript-pro11---1213# TypeScript Pro1415Advanced TypeScript 5.x type systems and end-to-end type safety.1617## When to use1819Advanced generics, conditional/mapped types, branded types, discriminated unions, monorepo project references, tRPC full-stack type safety, type guards.2021## Core workflow22231. **Analyze** — tsconfig, type coverage, build perf.242. **Design type-first APIs** — branded types, generics, utility types.253. **Implement** — type guards, discriminated unions, conditional types; `tsc --noEmit` to catch errors.264. **Optimize build** — project references, incremental compilation, tree shaking; re-run `tsc --noEmit`.275. **Test types** — verify with `type-coverage`; all public APIs have explicit return types. Iterate until zero errors.2829## Key patterns3031```typescript32// Branded types — prevent id mix-ups at compile time33type Brand<T, B extends string> = T & { readonly __brand: B };34type UserId = Brand<string, "UserId">;35const toUserId = (id: string): UserId => id as UserId;36```3738```typescript39// Discriminated union + exhaustive guard40type RequestState =41 | { status: "loading" }42 | { status: "success"; data: string[] }43 | { status: "error"; error: Error };4445function render(s: RequestState): string {46 switch (s.status) {47 case "loading": return "Loading…";48 case "success": return s.data.join(", ");49 case "error": return s.error.message;50 default: { const _x: never = s; throw new Error(_x); }51 }52}53```5455```json56// tsconfig.json essentials57{ "compilerOptions": {58 "strict": true, "noUncheckedIndexedAccess": true,59 "exactOptionalPropertyTypes": true, "isolatedModules": true,60 "declaration": true, "incremental": true } }61```6263## Constraints6465MUST: strict mode + all flags; type-first API design; branded types for domain modeling; `satisfies` for validation; discriminated unions for state machines; generate declaration files for libraries; optimize for inference.66MUST NOT: `any` without justification; skip type coverage on public APIs; mix type-only/value imports; disable strict null checks; needless `as` assertions; use enums (prefer `const` objects `as const`).6768## Output69701. Type definitions. 2. Implementation with type guards. 3. tsconfig if needed. 4. Brief note on type design.7172## Knowledge7374TypeScript 5.x, generics, conditional/mapped/template-literal types, discriminated unions, type guards, branded types, tRPC, project references, declaration files, const assertions, satisfies.