typescript-advanced-patterns_skill

This skill helps you master TypeScript advanced patterns to build type-safe APIs, complex domain models, and reusable libraries with compile-time guarantees.
  • Python

9

GitHub Stars

1

Bundled Files

2 months ago

Catalog Refreshed

4 months ago

First Indexed

Readme & install

Copy the install command, review bundled files from the catalogue, and read any extended description pulled from the listing source.

Installation

Preview and clipboard use veilstrat where the catalogue uses aiagentskills.

npx veilstrat add skill nickcrew/claude-cortex --skill typescript-advanced-patterns

  • SKILL.md5.5 KB

Overview

This skill provides expert guidance on using TypeScript's advanced type system to build robust, type-safe, and maintainable code. It focuses on patterns like conditional types, mapped types, discriminated unions, branded types, and advanced generics for compile-time guarantees. Use it to design APIs, domain models, and libraries that leverage strong typing to prevent classes of runtime errors.

How this skill works

The skill inspects design requirements and maps them to appropriate TypeScript patterns from a concise quick reference. It explains implementation steps: identify the need, load the pattern reference, implement with strict compiler settings, and validate both compile-time and runtime behavior. Examples, trade-offs, and common pitfalls accompany each pattern to guide safe adoption.

When to use it

  • Building type-safe APIs with strict request/response contracts
  • Modeling complex domains where invariants should be enforced at compile time
  • Creating reusable libraries that rely on precise type inference
  • Designing state machines, builders, or discriminated unions for exhaustive checks
  • Integrating runtime validation with type-level guarantees (e.g., zod)

Best practices

  • Enable TypeScript strict mode ("strict": true) and use const assertions for inference
  • Prefer unknown + type guards over any; validate before asserting types
  • Use readonly and branded types to enforce immutability and nominal distinctions
  • Keep types composable and avoid excessive deep nesting to reduce compile times
  • Document public API types with clear JSDoc and provide usage examples

Example use cases

  • Type-safe REST or GraphQL API contracts with mapped and conditional types
  • Domain-driven design: enforce business rules via branded types and discriminated unions
  • Library authoring: expose fluent builder APIs with progressive generic constraints
  • State machines: use discriminated unions for exhaustive handling and compile-time checks
  • Runtime-validated inputs: combine zod schemas with inferred TypeScript types

FAQ

Deep or highly recursive types can slow the compiler; prefer shallow, composable types and measure impact. Use utility libraries judiciously.

When should I prefer type guards over assertions?

Use type guards when runtime validation is needed. Assertions skip runtime checks and are unsafe unless you can guarantee types externally.

Built by
VeilStrat
AI signals for GTM teams
© 2026 VeilStrat. All rights reserved.All systems operational