Skip to main content
skill CX Codex

typescript-patterns — Claude Code skill: what it does, how to install

Provides advanced strict-mode TypeScript patterns to enforce type safety and stop runtime errors before code runs.

MIT 202 installs ★ 29 updated 2026-08-17

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add oakoss/agent-skills --skill typescript-patterns -a claude-code
Open on GitHub

What typescript-patterns does

This skill guides the agent through strict TypeScript patterns, steering it away from bare any casts. It supplies concrete rules for discriminated unions and generic constraints. Instead of forced assertions, it instructs the model to preserve exact types with satisfies and validate data with unknown.

It is strictly an advanced reference. You will not find basic tutorials on classes or interfaces here, nor will you find bundler setup guides. The instructions expect strict compiler flags such as noUncheckedIndexedAccess. If you need build configuration or migration steps from legacy JavaScript, this skill will not help you because it focuses purely on type-level mechanics.

What it helps with

  • Eliminate any types by applying unknown and runtime type guards
  • Enforce exhaustive switch checks on discriminated unions with never
  • Prevent type widening on configuration objects using satisfies
  • Constrain generic parameters with explicit extends bounds

Example prompts for the agent

  • Refactor this API response handler to use type guards instead of any
  • Add an exhaustive status check with never to this discriminated union
  • Replace unsafe as const type casts in this config with the satisfies operator

How to install typescript-patterns

1Skills CLI (Vercel)

npx skills add oakoss/agent-skills --skill typescript-patterns -a claude-code

2Manually: put the files in place

~/.claude/skills/typescript-patterns/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/typescript-patterns/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about typescript-patterns

How do I install typescript-patterns in Claude Code?

Run npx skills add oakoss/agent-skills --skill typescript-patterns -a claude-code in your terminal.

What does the typescript-patterns skill do?

It provides rules and patterns for strict-mode TypeScript development, helping the agent handle generics, conditional types, and runtime narrowing.

When should you avoid using this skill?

Avoid it for introductory TypeScript tutorials, JavaScript-to-TypeScript code migrations, or project build tool setup.

Source text

SKILL.md · MIT
---
name: typescript-patterns
description: '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.'
license: MIT
metadata:
  author: oakoss
  version: '1.1'
  source: 'https://www.typescriptlang.org/docs/'
user-invocable: false
---

# TypeScript Patterns

## Overview

Advanced TypeScript patterns that use the type system to prevent runtime errors. Focuses on strict mode TypeScript with patterns for type inference, narrowing, and compile-time validation. **Not** a beginner tutorial.

**When to use:** Building type-safe APIs, complex data transformations, library authoring, preventing runtime errors through types, working with strict mode flags.

**When NOT to use:** Learning TypeScript basics (primitives, interfaces, classes), JavaScript-to-TypeScript migration guidance, tooling setup, or build configuration.

## Quick Reference

| Pattern               | API                                  | Key Points                           |
| --------------------- | ------------------------------------ | ------------------------------------ |
| Utility types         | `Pick<T, K>`, `Omit<T, K>`           | Extract or exclude properties        |
| Partial/Required      | `Partial<T>`, `Required<T>`          | Make properties optional or required |
| Record type           | `Record<K, V>`                       | Object with known keys               |
| Awaited type          | `Awaited<T>`                         | Unwrap Promise return types          |
| ReturnType/Parameters | `ReturnType<F>`, `Parameters<F>`     | Extract function types               |
| Generic constraints   | `<T extends Type>`                   | Constrain generic parameters         |
| Type inference        | `type Inferred = typeof value`       | Let TypeScript infer from values     |
| Type guards           | `typeof`, `instanceof`, `in`         | Narrow types at runtime              |
| Custom type guards    | `(x): x is Type`                     | User-defined narrowing functions     |
| Inferred predicates   | `(x) => x !== null`                  | Auto-inferred type predicate filters |
| Discriminated unions  | Union with literal `type` property   | Exhaustive pattern matching          |
| Conditional types     | `T extends U ? X : Y`                | Type-level conditionals              |
| Mapped types          | `{ [K in keyof T]: T[K] }`           | Transform all properties             |
| Template literals     | `` `${A}-${B}` ``                    | String literal type manipulation     |
| Const assertions      | `as const`                           | Narrowest possible literal types     |
| Satisfies operator    | `value satisfies Type`               | Type check without widening          |
| NoInfer utility       | `NoInfer<T>`                         | Prevent inference from a position    |
| Const type params     | `<const T extends Type>`             | Narrow inference without `as const`  |
| Inline type imports   | `import { type User }`               | Import types explicitly              |
| Module augmentation   | `declare module 'lib' { ... }`       | Extend third-party types             |
| Assertion functions   | `function assert(x): asserts x is T` | Throw if type guard fails            |

## Common Mistakes

| Mistake                              | Correct Pattern                                |
| ------------------------------------ | ---------------------------------------------- |
| Using `any` without justification    | Use `unknown` and narrow with type guards      |
| 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 `noUncheckedIndexedAccess`              |
| `as Type` casting unsafe values      | Use `satisfies Type` to preserve narrow types  |
| Inline objects in generics           | Extract to `const` or type alias               |
| Omitting `extends` in constraints    | Always constrain generics when possible        |
| Using `Parameters<typeof fn>[0]`     | Type the parameter directly in function        |
| Not handling union exhaustiveness    | Use `never` checks in switch/if-else           |
| `value as const satisfies Type`      | Use `satisfies Type` then `as const` if needed |

## Delegation

- **Pattern discovery**: Use `Explore` agent to find existing patterns in codebase
- **Type error debugging**: Use `Task` agent for multi-step type resolution
- **Code review**: Delegate to `code-reviewer` skill for type safety audit

## References

- [Type utilities (Pick, Omit, Partial, Required, Record, Extract, Exclude, ReturnType, Parameters, Awaited)](references/type-utilities.md)
- [Generics (constraints, inference, default parameters, variance)](references/generics.md)
- [Type guards and narrowing (typeof, instanceof, in, custom guards, assertion functions)](references/type-guards.md)
- [Discriminated unions (exhaustive checking, never type, tagged unions)](references/discriminated-unions.md)
- [Conditional types (distributive conditionals, infer keyword, type-level logic)](references/conditional-types.md)
- [Mapped types (key remapping, template literals, modifiers)](references/mapped-types.md)
- [Strict mode patterns (noUncheckedIndexedAccess, exactOptionalPropertyTypes, const assertions, satisfies)](references/strict-mode.md)
- [Module patterns (inline type imports, declaration files, module augmentation, ambient types)](references/module-patterns.md)
- [Modern idioms (eslint-plugin-unicorn patterns, modern array/string/DOM APIs, ES modules)](references/modern-idioms.md)

© oakoss · MIT · oakoss/agent-skills

Similar skills

All skills for Programming languages →

From the same set106

The whole set →
tanstack-form This skill guides TanStack Form v1 usage in React, covering state, validation, and submission. Use it for complex forms and changing field lists. CX Codex +1 222installs knowledge-graph-builder The knowledge-graph-builder skill guides knowledge-graph design, graph database choice, and graph-plus-vector retrieval. Use it for Graph RAG, entity resolution, and fact checks. CX Codex +1 222installs pino-logging Set up structured Pino logging in Node.js, including request context, sensitive-field redaction, transports, and framework integrations. CX Codex +1 217installs database-security database-security audits the data layer of Supabase, Postgres and Convex apps: RLS coverage, policy holes, service-role leaks, audit logging. Useful before a release or after an incident. CX Codex +1 208installs react-patterns react-patterns is a Claude Code skill that covers React 19 patterns, state choices, data loading with use(), and reducing needless re-renders when building or reviewing components. CX Codex +1 201installs ci-cd-architecture ci-cd-architecture is a Claude Code skill for planning CI/CD pipelines, comparing deployment platforms, and securing GitHub Actions. It supports preparing a project for production or changing its delivery setup. CX Codex +1 199installs openapi Guides the agent in writing OpenAPI 3.1 schemas and generating TypeScript clients. Ideal for REST API contract design and schema validation. CX Codex +1 197installs css-animation-patterns css-animation-patterns is a Claude Code skill for CSS animation work. It guides agents on composite properties, transitions, and newer motion APIs. CX Codex +1 196installs

Project sponsors

Companies that keep this analytics open