Skip to main content
skill CX Codex

typescript-advanced-patterns · nickcrew — Claude Code skill: features and install

The typescript-advanced-patterns skill helps apply advanced TypeScript types to APIs and domain models. Use it when compile-time rules need to express states, constraints, or distinct identifiers.

MIT 174 installs ★ 71 updated 2026-06-29

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

What typescript-advanced-patterns does

The skill guides the choice of TypeScript patterns, including conditional and mapped types, template literal types, type guards, discriminated unions, branded types, and constrained generics. These techniques can represent API contracts and application states in the type system.

Its workflow starts by identifying the requirement, then opening a relevant guide in references, implementing the pattern, and checking both types and runtime behaviour. The reference files cover topics such as type testing and common pitfalls. It recommends enabling strict in tsconfig.json; deeply nested types can slow compilation, so keep them shallow.

What it helps with

  • define explicit contracts for a type-safe API
  • model application states with discriminated unions
  • keep distinct string identifiers from being mixed
  • build a fluent API with progressive generic constraints
  • review types for unsafe assertions and excessive nesting

Example prompts for the agent

  • Design a type-safe API for these functions using suitable TypeScript patterns.
  • Represent loading, success, and error states as a discriminated union.
  • Review these types for excessive nesting and suggest a simpler structure.

How to install typescript-advanced-patterns

1Skills CLI (Vercel)

npx skills add NickCrew/Claude-Cortex --skill typescript-advanced-patterns -a claude-code

2Manually: put the files in place

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

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

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

Questions about typescript-advanced-patterns

How do I install typescript-advanced-patterns in Claude Code?

Run npx skills add NickCrew/Claude-Cortex --skill typescript-advanced-patterns -a claude-code. The skill file is at ~/.claude/skills/typescript-advanced-patterns/SKILL.md.

What does typescript-advanced-patterns do?

It helps apply advanced TypeScript features to API contracts and domain models. The skill includes guidance on type patterns, validation, and common mistakes.

Which TypeScript patterns does the skill cover?

It covers conditional and mapped types, type guards, discriminated unions, branded types, generics, and type inference, with separate guides in references.

Source text

SKILL.md · MIT
---
name: typescript-advanced-patterns
description: Advanced TypeScript patterns for type-safe, maintainable code using sophisticated type system features. Use when building type-safe APIs, implementing complex domain models, or leveraging TypeScript's advanced type capabilities.
keywords:
  - TypeScript
  - advanced types
  - branded types
  - conditional types
  - discriminated union
  - generic constraints
  - mapped types
  - template literal types
  - type guard
  - type inference
file_patterns:
  - '**/*.ts'
  - '**/*.tsx'
  - '**/package.json'
  - '**/tsconfig.json'
confidence: 0.78
---

# TypeScript Advanced Patterns

Expert guidance for leveraging TypeScript's advanced type system features to build robust, type-safe applications with sophisticated type inference, compile-time guarantees, and maintainable domain models.

## When to Use This Skill

- Building type-safe APIs with strict contracts and validation
- Implementing complex domain models with compile-time enforcement
- Creating reusable libraries with sophisticated type inference
- Enforcing business rules through the type system
- Building type-safe state machines and builders
- Developing framework integrations requiring advanced types
- Implementing runtime validation with type-level guarantees

## Core Concepts

TypeScript's type system enables compile-time safety through:

1. **Conditional Types**: Type selection based on conditions (type-level if/else)
2. **Mapped Types**: Transform object types systematically (Partial, Readonly, Pick, Omit)
3. **Template Literal Types**: String manipulation at compile time
4. **Type Guards**: Runtime checking with type narrowing (`value is Type`)
5. **Discriminated Unions**: Type-safe state machines with exhaustiveness checking
6. **Branded Types**: Nominal types for preventing primitive mixing
7. **Builder Pattern**: Type-safe fluent APIs with progressive type constraints
8. **Advanced Generics**: Constraints, inference, and higher-kinded type patterns
9. **Utility Types**: Deep transformations and compositions
10. **Type Inference**: Const assertions and contextual typing

## Quick Reference

Load detailed references on-demand:

| Topic | Reference File |
|-------|----------------|
| Conditional Types | `skills/typescript-advanced-patterns/references/conditional-types.md` |
| Mapped Types | `skills/typescript-advanced-patterns/references/mapped-types.md` |
| Template Literal Types | `skills/typescript-advanced-patterns/references/template-literal-types.md` |
| Type Guards | `skills/typescript-advanced-patterns/references/type-guards.md` |
| Discriminated Unions | `skills/typescript-advanced-patterns/references/discriminated-unions.md` |
| Branded Types | `skills/typescript-advanced-patterns/references/branded-types.md` |
| Builder Pattern | `skills/typescript-advanced-patterns/references/builder-pattern.md` |
| Advanced Generics | `skills/typescript-advanced-patterns/references/advanced-generics.md` |
| Utility Types | `skills/typescript-advanced-patterns/references/utility-types.md` |
| Type Inference | `skills/typescript-advanced-patterns/references/type-inference.md` |
| Decorators | `skills/typescript-advanced-patterns/references/decorators.md` |
| Performance Best Practices | `skills/typescript-advanced-patterns/references/performance-best-practices.md` |
| Common Pitfalls | `skills/typescript-advanced-patterns/references/common-pitfalls.md` |
| Testing Types | `skills/typescript-advanced-patterns/references/testing-types.md` |

## Implementation Workflow

### 1. Identify Pattern Need
- Analyze type safety requirements
- Identify runtime vs compile-time constraints
- Choose appropriate pattern from Quick Reference

### 2. Load Reference
- Read specific reference file for pattern
- Review examples and use cases
- Understand trade-offs

### 3. Implement Pattern
- Start simple, add complexity as needed
- Use strict mode (`tsconfig.json` with `"strict": true`)
- Test with type assertions

### 4. Validate
- Ensure type errors caught at compile time
- Verify runtime behavior matches types
- Check performance (avoid excessive type complexity)

### 5. Document
- Add JSDoc comments for public APIs
- Document type constraints and assumptions
- Provide usage examples

## Common Mistakes to Avoid

1. **Using `any` instead of `unknown`**: Loses all type safety
   - Use `unknown` and type guards instead

2. **Type assertions without validation**: Unsafe runtime behavior
   - Prefer type guards (`value is Type`) over `as Type`

3. **Overusing generics**: Unnecessary complexity
   - Only use generics when types truly vary

4. **Deep type nesting**: Slow compilation, hard to debug
   - Keep types composable and shallow

5. **Forgetting `readonly`**: Accidental mutations
   - Mark immutable data structures as `readonly`

6. **Not enabling strict mode**: Missing null checks and type errors
   - Always use `"strict": true` in `tsconfig.json`

7. **Mixing type and interface incorrectly**: Confusing semantics
   - Use `type` for unions/utilities, `interface` for object shapes

## Quick Patterns

### Type-Safe ID
```typescript
type UserId = string & { readonly __brand: 'UserId' };
function createUserId(id: string): UserId { return id as UserId; }
```

### Discriminated Union
```typescript
type State =
  | { status: 'loading' }
  | { status: 'success'; data: string }
  | { status: 'error'; error: Error };
```

### Mapped Type Transformation
```typescript
type Readonly<T> = { readonly [P in keyof T]: T[P] };
type Partial<T> = { [P in keyof T]?: T[P] };
```

### Type Guard
```typescript
function isString(value: unknown): value is string {
  return typeof value === 'string';
}
```

## Resources

- **TypeScript Handbook**: https://www.typescriptlang.org/docs/handbook/
- **Type Challenges**: https://github.com/type-challenges/type-challenges
- **ts-toolbelt**: Advanced type utilities library
- **zod**: Runtime validation with TypeScript inference
- **tsd**: Test TypeScript type definitions

© NickCrew · MIT · NickCrew/Claude-Cortex

Similar skills

All skills for Programming languages →

typescript-advanced-patterns by other authors comes first.

typescript-advanced-patterns pproenca typescript-advanced-patterns — a TypeScript skill with 40 rules on type-level programming, library API design and deeper use of TS 5.x features. Useful once plain typings stop being enough. CX Codex +1 162installs typescript-advanced-patterns curiositech The typescript-advanced-patterns skill applies advanced TypeScript type patterns to domain models, type-safe APIs, generic utilities, and compile-time checks. CX Codex +1 148installs typescript-advanced-types Seth Hobson typescript-advanced-types guides an agent through advanced TypeScript types, from generics to conditional and mapped types. Use it for typed libraries, API clients, or strict configuration objects. CX Codex +1 92,169installs typescript-advanced Pedro Nauck typescript-advanced guides agents through advanced TypeScript types and compile-time contracts. Use it when generic inference or reusable type utilities are the hard part. CX Codex +1 587installs typescript-patterns oakoss Provides advanced strict-mode TypeScript patterns to enforce type safety and stop runtime errors before code runs. CX Codex +1 202installs typescript-react-patterns agent-skills typescript-react-patterns — a skill with 33 TypeScript rules for React: props, hooks, events, refs, generics and context. Useful when the agent writes components and fights type errors. CX Codex +1 1,100installs dataverse-python-advanced-patterns official github dataverse-python-advanced-patterns guides GitHub Copilot to generate Dataverse Python code with error recovery, batch work, and OData query patterns. CX Codex +1 9,213installs typescript-e2e-testing bmad-labs The typescript-e2e-testing skill for Claude Code guides E2E and integration testing in TypeScript/NestJS projects. It covers Jest, supertest, Docker services, and Given-When-Then cases. CX Codex +1 2,300installs

From the same set21

The whole set →
threat-modeling-techniques threat-modeling-techniques — a skill for threat modeling: walks the system through STRIDE, builds attack trees and scores risk with DREAD. Best used before the code exists. CX Codex +1 357installs token-efficiency token-efficiency — a Claude Code skill that switches the agent to compact notation — symbols and abbreviations instead of full sentences. Kicks in when the context window is nearly full or a short status line is enough. CX Codex +1 245installs repo-cleanup repo-cleanup — a skill for structured repository cleanup: removes dead code, unused dependencies, outdated docs, and flaky tests with usage checks, archiving, and validation steps built in. CX Codex +1 183installs helm-chart-patterns helm-chart-patterns is a Claude Code skill for developing Kubernetes Helm charts, covering template structure, values.schema.json validation, lifecycle hooks, and multi-environment setups. CX Codex +1 179installs code-explanation The code-explanation skill explains code, architecture, and system behavior at a depth that matches the reader. Use it for walkthroughs, teaching, and knowledge transfer. CX Codex +1 173installs security-testing-patterns security-testing-patterns guides security testing workflows across SAST, SCA, DAST, and OWASP API audits. Use it to build CI/CD scanning pipelines and triage vulnerabilities. CX Codex +1 154installs secure-coding-practices secure-coding-practices is a Claude Code skill for applying defensive coding patterns to authentication, user input, and sensitive data. It also supports security-focused code reviews. CX Codex +1 134installs ux-review ux-review reviews a component or flow from three angles: usability heuristics, WCAG 2.1 AA accessibility and interaction design. Comes back with a prioritized report. CX Codex +1 119installs

Project sponsors

Companies that keep this analytics open