$npx -y skills add jeffallan/claude-skills --skill typescript-proImplements advanced TypeScript type systems, creates custom type guards, utility types, and branded types, and configures tRPC for end-to-end type safety. Use when building TypeScript applications requiring advanced generics, conditional or mapped types, discriminated unions, mon
| 1 | # TypeScript Pro |
| 2 | |
| 3 | ## Core Workflow |
| 4 | |
| 5 | 1. **Analyze type architecture** - Review tsconfig, type coverage, build performance |
| 6 | 2. **Design type-first APIs** - Create branded types, generics, utility types |
| 7 | 3. **Implement with type safety** - Write type guards, discriminated unions, conditional types; run `tsc --noEmit` to catch type errors before proceeding |
| 8 | 4. **Optimize build** - Configure project references, incremental compilation, tree shaking; re-run `tsc --noEmit` to confirm zero errors after changes |
| 9 | 5. **Test types** - Confirm type coverage with a tool like `type-coverage`; validate that all public APIs have explicit return types; iterate on steps 3–4 until all checks pass |
| 10 | |
| 11 | ## Reference Guide |
| 12 | |
| 13 | Load detailed guidance based on context: |
| 14 | |
| 15 | | Topic | Reference | Load When | |
| 16 | |-------|-----------|-----------| |
| 17 | | Advanced Types | `references/advanced-types.md` | Generics, conditional types, mapped types, template literals | |
| 18 | | Type Guards | `references/type-guards.md` | Type narrowing, discriminated unions, assertion functions | |
| 19 | | Utility Types | `references/utility-types.md` | Partial, Pick, Omit, Record, custom utilities | |
| 20 | | Configuration | `references/configuration.md` | tsconfig options, strict mode, project references | |
| 21 | | Patterns | `references/patterns.md` | Builder pattern, factory pattern, type-safe APIs | |
| 22 | |
| 23 | ## Code Examples |
| 24 | |
| 25 | ### Branded Types |
| 26 | ```typescript |
| 27 | // Branded type for domain modeling |
| 28 | type Brand<T, B extends string> = T & { readonly __brand: B }; |
| 29 | type UserId = Brand<string, "UserId">; |
| 30 | type OrderId = Brand<number, "OrderId">; |
| 31 | |
| 32 | const toUserId = (id: string): UserId => id as UserId; |
| 33 | const toOrderId = (id: number): OrderId => id as OrderId; |
| 34 | |
| 35 | // Usage — prevents accidental id mix-ups at compile time |
| 36 | function getOrder(userId: UserId, orderId: OrderId) { /* ... */ } |
| 37 | ``` |
| 38 | |
| 39 | ### Discriminated Unions & Type Guards |
| 40 | ```typescript |
| 41 | type LoadingState = { status: "loading" }; |
| 42 | type SuccessState = { status: "success"; data: string[] }; |
| 43 | type ErrorState = { status: "error"; error: Error }; |
| 44 | type RequestState = LoadingState | SuccessState | ErrorState; |
| 45 | |
| 46 | // Type predicate guard |
| 47 | function isSuccess(state: RequestState): state is SuccessState { |
| 48 | return state.status === "success"; |
| 49 | } |
| 50 | |
| 51 | // Exhaustive switch with discriminated union |
| 52 | function renderState(state: RequestState): string { |
| 53 | switch (state.status) { |
| 54 | case "loading": return "Loading…"; |
| 55 | case "success": return state.data.join(", "); |
| 56 | case "error": return state.error.message; |
| 57 | default: { |
| 58 | const _exhaustive: never = state; |
| 59 | throw new Error(`Unhandled state: ${_exhaustive}`); |
| 60 | } |
| 61 | } |
| 62 | } |
| 63 | ``` |
| 64 | |
| 65 | ### Custom Utility Types |
| 66 | ```typescript |
| 67 | // Deep readonly — immutable nested objects |
| 68 | type DeepReadonly<T> = { |
| 69 | readonly [K in keyof T]: T[K] extends object ? DeepReadonly<T[K]> : T[K]; |
| 70 | }; |
| 71 | |
| 72 | // Require exactly one of a set of keys |
| 73 | type RequireExactlyOne<T, Keys extends keyof T = keyof T> = |
| 74 | Pick<T, Exclude<keyof T, Keys>> & |
| 75 | { [K in Keys]-?: Required<Pick<T, K>> & Partial<Record<Exclude<Keys, K>, never>> }[Keys]; |
| 76 | ``` |
| 77 | |
| 78 | ### Recommended tsconfig.json |
| 79 | ```json |
| 80 | { |
| 81 | "compilerOptions": { |
| 82 | "target": "ES2022", |
| 83 | "module": "NodeNext", |
| 84 | "moduleResolution": "NodeNext", |
| 85 | "strict": true, |
| 86 | "noUncheckedIndexedAccess": true, |
| 87 | "noImplicitOverride": true, |
| 88 | "exactOptionalPropertyTypes": true, |
| 89 | "isolatedModules": true, |
| 90 | "declaration": true, |
| 91 | "declarationMap": true, |
| 92 | "incremental": true, |
| 93 | "skipLibCheck": false |
| 94 | } |
| 95 | } |
| 96 | ``` |
| 97 | |
| 98 | ## Constraints |
| 99 | |
| 100 | ### MUST DO |
| 101 | - Enable strict mode with all compiler flags |
| 102 | - Use type-first API design |
| 103 | - Implement branded types for domain modeling |
| 104 | - Use `satisfies` operator for type validation |
| 105 | - Create discriminated unions for state machines |
| 106 | - Use `Annotated` pattern with type predicates |
| 107 | - Generate declaration files for libraries |
| 108 | - Optimize for type inference |
| 109 | |
| 110 | ### MUST NOT DO |
| 111 | - Use explicit `any` without justification |
| 112 | - Skip type coverage for public APIs |
| 113 | - Mix type-only and value imports |
| 114 | - Disable strict null checks |
| 115 | - Use `as` assertions without necessity |
| 116 | - Ignore compiler performance warnings |
| 117 | - Skip declaration file generation |
| 118 | - Use enums (prefer const objects with `as const`) |
| 119 | |
| 120 | ## Output Templates |
| 121 | |
| 122 | When implementing TypeScript features, provide: |
| 123 | 1. Type definitions (interfaces, types, generics) |
| 124 | 2. Implementation with type guar |