typescript-patterns

Apply advanced TypeScript patterns for strict mode development.

14|5|Updated Jan 29, 2026
One-click install
npx skills add https://github.com/oakoss/agent-skills --skill typescript-patterns-oakoss
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: typescript-patterns
Source: https://github.com/oakoss/agent-skills/tree/main/skills/typescript-patterns
Command: npx skills add https://github.com/oakoss/agent-skills --skill typescript-patterns-oakoss

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill helps developers write more robust, type-safe, and maintainable TypeScript code by leveraging advanced language features and patterns, preventing runtime errors and improving code quality.

Core Features & Use Cases

  • Advanced Type Utilities: Utilize Pick, Omit, Partial, Record, Awaited, and more for precise type manipulation.
  • Generics and Constraints: Build flexible and reusable code with generic functions and types, enforcing type safety.
  • Type Guards and Narrowing: Implement runtime checks to safely narrow down union types.
  • Discriminated Unions: Create robust state management and event handling with tagged unions.
  • Conditional and Mapped Types: Dynamically transform types based on conditions or iterate over object keys.
  • Strict Mode Patterns: Adopt best practices for strict TypeScript configurations, including const assertions and the satisfies operator.
  • Module Patterns: Understand inline type imports, declaration files, and module augmentation for better code organization.
  • Use Case: When building a complex API client, use discriminated unions to handle different response types, generics for reusable data fetching functions, and utility types to shape request and response payloads accurately.

Quick Start

Explain the concept of discriminated unions in TypeScript, providing a clear example.

Frequently Asked Questions about typescript-patterns

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I use discriminated unions in TypeScript for state management?

Discriminated unions in TypeScript use a common literal property to create tagged unions, allowing the compiler to safely narrow down types. This pattern enables robust state management and type-safe event handling by checking the tag before accessing specific properties.

What is the best way to build type-safe API clients with generics in TypeScript?

Building type-safe API clients with generics involves creating reusable data fetching functions that enforce type constraints. You can use utility types like `Pick` and `Omit` to shape request and response payloads accurately, ensuring end-to-end type safety.

How does the TypeScript satisfies operator work in strict mode?

The TypeScript `satisfies` operator validates that an object matches a specific type without losing its precise literal types. It is a strict mode best practice that ensures type safety while preserving narrow inferred types for subsequent property access.

How do I create type guards to narrow complex union types?

Type guards in TypeScript are runtime checks that safely narrow down union types. By implementing custom type predicate functions, you can check specific properties or tags to guarantee type safety and prevent runtime errors during execution.

When should I use conditional and mapped types in TypeScript?

Conditional and mapped types in TypeScript are used to dynamically transform types based on conditions or iterate over object keys. They are essential for generating complex type utilities and enforcing strict type safety across reusable code components.

How do I debug complex TypeScript type errors with strict mode enabled?

Debugging complex TypeScript type errors in strict mode requires analyzing type inference failures and narrowing logic. Leveraging advanced patterns like const assertions and precise utility types helps pinpoint mismatches and enforce modern JavaScript idioms.