typescript-modern

Guide advanced TypeScript patterns including utility types, generics, and discriminated unions.

1|Updated Mar 1, 2026
One-click install
npx skills add https://github.com/hjemmesidekongen/ai --skill typescript-modern-hjemmesidekongen
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: typescript-modern
Source: https://github.com/hjemmesidekongen/ai/tree/main/plugins/smedjen/skills/typescript-modern
Command: npx skills add https://github.com/hjemmesidekongen/ai --skill typescript-modern-hjemmesidekongen

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill helps developers write more robust, maintainable, and type-safe TypeScript code by leveraging advanced features and patterns beyond the basics.

Core Features & Use Cases

  • Advanced Type Constructs: Deep dive into utility types, generics, discriminated unions, and template literal types.
  • Type Safety: Learn to avoid common pitfalls like any abuse and ensure exhaustiveness in conditional logic.
  • Use Case: Refactor a complex state management system to use discriminated unions for precise state transitions, preventing runtime errors and improving developer experience.

Quick Start

Learn how to use branded types to create distinct string types for user IDs and order IDs.

Frequently Asked Questions about typescript-modern

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

FAQPage Schema
How do I use discriminated unions in TypeScript to manage complex state transitions?

TypeScript discriminated unions model precise state transitions by tagging variant types, preventing invalid runtime states. This pattern eliminates common anti-patterns like `any` abuse, ensuring exhaustive type checking and code maintainability during complex state refactors.

What's the best way to create distinct string types for IDs in TypeScript?

Use TypeScript branded types to create distinct string types for identifiers like user IDs and order IDs. This type-level programming technique prevents accidental cross-assignment of structurally identical strings, enhancing safety without runtime overhead.

How do template literal types work in TypeScript for type-level programming?

Template literal types in TypeScript enable type-level programming by constructing string union types from literal substitutions. This advanced construct allows developers to enforce strict string formats and derive utility types directly from string patterns.

When should I use the TypeScript satisfies operator instead of type annotations?

Use the TypeScript `satisfies` operator when you need to verify an expression matches a type without widening it. This ensures type safety while preserving narrower inferred types for subsequent property access, preventing common type inference pitfalls.

How do I ensure exhaustiveness in conditional logic with utility types and generics?

Combine TypeScript utility types, generics, and discriminated unions to enforce exhaustiveness in conditional logic checks. This approach leverages the `never` type in switch statements to catch missing cases at compile time, preventing runtime errors.

Can I extend existing module declarations in TypeScript without modifying original source files?

TypeScript module augmentation allows you to extend existing module declarations by merging custom types into ambient scopes. This prevents type conflicts and enhances maintainability when adding functionality to third-party libraries or internal frameworks.