Loading...
Loading...
Advanced TypeScript patterns for strict mode development. Covers type utilities (Pick, Omit, Partial, Record, Awaited), generics with constraints and inference, type guards and narrowing, discriminated unions, conditional and mapped types, template literal types, const assertions, satisfies operator, module patterns, and modern JavaScript idioms (eslint-plugin-unicorn). Use when building type-safe APIs, preventing runtime errors through types, working with strict TypeScript configuration, debugging complex type errors, or enforcing modern JS idioms. Use for generics, type guards, utility types, strict mode, type inference, narrowing, type safety, const assertions, satisfies, module augmentation, unicorn, for-of, modern-js.
npx skill4agent add oakoss/agent-skills typescript-patterns| Pattern | API | Key Points |
|---|---|---|
| Utility types | | Extract or exclude properties |
| Partial/Required | | Make properties optional or required |
| Record type | | Object with known keys |
| Awaited type | | Unwrap Promise return types |
| ReturnType/Parameters | | Extract function types |
| Generic constraints | | Constrain generic parameters |
| Type inference | | Let TypeScript infer from values |
| Type guards | | Narrow types at runtime |
| Custom type guards | | User-defined narrowing functions |
| Inferred predicates | | Auto-inferred type predicate filters |
| Discriminated unions | Union with literal | Exhaustive pattern matching |
| Conditional types | | Type-level conditionals |
| Mapped types | | Transform all properties |
| Template literals | | String literal type manipulation |
| Const assertions | | Narrowest possible literal types |
| Satisfies operator | | Type check without widening |
| NoInfer utility | | Prevent inference from a position |
| Const type params | | Narrow inference without |
| Inline type imports | | Import types explicitly |
| Module augmentation | | Extend third-party types |
| Assertion functions | | Throw if type guard fails |
| Mistake | Correct Pattern |
|---|---|
Using | Use |
| Manual type assertions everywhere | Let inference work, type function returns |
| Destructuring before type narrowing | Keep object intact for discriminated unions |
| Index access without undefined check | Enable |
| Use |
| Inline objects in generics | Extract to |
Omitting | Always constrain generics when possible |
Using | Type the parameter directly in function |
| Not handling union exhaustiveness | Use |
| Use |
ExploreTaskcode-reviewer