
typescript-advanced-patterns
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.
- Installs
- 174
- Last 24h
- —
- Trending rank
- —
- Security
- Not audited
Install
Works with every agent the skills CLI supports.
npx skills add https://github.com/nickcrew/claude-cortex --skill typescript-advanced-patterns- 01
Install
Run the command in your project. The CLI asks which agents to install for.
- 02
Describe the task
Ask your agent for something this skill covers. It loads typescript-advanced-patterns automatically when relevant.
- 03
Review the result
The agent follows the SKILL.md steps, scripts and references bundled with the skill.
SKILL.md
The instructions your agent reads when the skill is triggered.
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:
- Conditional Types: Type selection based on conditions (type-level if/else)
- Mapped Types: Transform object types systematically (Partial, Readonly, Pick, Omit)
- Template Literal Types: String manipulation at compile time
- Type Guards: Runtime checking with type narrowing (
value is Type) - Discriminated Unions: Type-safe state machines with exhaustiveness checking
- Branded Types: Nominal types for preventing primitive mixing
- Builder Pattern: Type-safe fluent APIs with progressive type constraints
- Advanced Generics: Constraints, inference, and higher-kinded type patterns
- Utility Types: Deep transformations and compositions
- 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.jsonwith"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
-
Using
anyinstead ofunknown: Loses all type safety- Use
unknownand type guards instead
- Use
-
Type assertions without validation: Unsafe runtime behavior
- Prefer type guards (
value is Type) overas Type
- Prefer type guards (
-
Overusing generics: Unnecessary complexity
- Only use generics when types truly vary
-
Deep type nesting: Slow compilation, hard to debug
- Keep types composable and shallow
-
Forgetting
readonly: Accidental mutations- Mark immutable data structures as
readonly
- Mark immutable data structures as
-
Not enabling strict mode: Missing null checks and type errors
- Always use
"strict": trueintsconfig.json
- Always use
-
Mixing type and interface incorrectly: Confusing semantics
- Use
typefor unions/utilities,interfacefor object shapes
- Use
Quick Patterns
Type-Safe ID
type UserId = string & { readonly __brand: 'UserId' };
function createUserId(id: string): UserId { return id as UserId; }
Discriminated Union
type State =
| { status: 'loading' }
| { status: 'success'; data: string }
| { status: 'error'; error: Error };
Mapped Type Transformation
type Readonly<T> = { readonly [P in keyof T]: T[P] };
type Partial<T> = { [P in keyof T]?: T[P] };
Type Guard
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
FAQ
What does the typescript-advanced-patterns skill do?
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.
How do I install typescript-advanced-patterns?
Run npx skills add https://github.com/nickcrew/claude-cortex --skill typescript-advanced-patterns in your project. The skills CLI detects the agents you use and copies the skill into the right folder. For Claude Code you can also place the skill folder at ~/.claude/skills/typescript-advanced-patterns/ (personal) or .claude/skills/typescript-advanced-patterns/ (project).
Which AI agents can use typescript-advanced-patterns?
Any agent that supports the open Agent Skills format (a folder with a SKILL.md file), including Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, Windsurf, Cline, OpenCode and more.
Is typescript-advanced-patterns safe to install?
No partner security audit is available yet. Skills can run commands and scripts, so read the SKILL.md and any bundled files before installing.
Who maintains typescript-advanced-patterns?
It is published by nickcrew in nickcrew/claude-cortex. It has 174 recorded installs.
More from nickcrew/claude-cortex
react-performance-optimization
nickcrew/claude-cortex
React performance optimization patterns using memoization, code splitting, and efficient rendering strategies. Use when optimizing slow React applications, reducing bundle size, or improving user experience with large datasets.
owasp-top-10
nickcrew/claude-cortex
OWASP Top 10 security vulnerabilities with detection and remediation patterns. Use when conducting security audits, implementing secure coding practices, or reviewing code for common security vulnerabilities.
ui-design-aesthetics
nickcrew/claude-cortex
Generates high-quality, non-generic UI designs with a focus on performance, progressive disclosure, and distinctive aesthetics.
threat-modeling-techniques
nickcrew/claude-cortex
Open the skill to read its SKILL.md instructions.
token-efficiency
nickcrew/claude-cortex
Compressed communication using symbols and abbreviations. Use when context is limited or brevity is needed.
helm-chart-patterns
nickcrew/claude-cortex
Helm chart development patterns for packaging and deploying Kubernetes applications. Use when creating reusable Helm charts, managing multi-environment deployments, or building application catalogs for Kubernetes.
Popular code quality & workflow skills
grill-me
mattpocock/skills
A relentless interview to sharpen a plan or design.
improve-codebase-architecture
mattpocock/skills
Scan a codebase for deepening opportunities, present them as a visual HTML report, then grill through whichever one you pick.
handoff
mattpocock/skills
Compact the current conversation into a handoff document for another agent to pick up.
domain-modeling
mattpocock/skills
Build and sharpen a project's domain model. Use when discussing codebase terminology, writing or editing a GLOSSARY.md, or recording or editing an ADR.
codebase-design
mattpocock/skills
Shared vocabulary for designing deep modules. Use when the user wants to design or improve a module's interface, find deepening opportunities, decide where a seam goes, make code more testable or AI-navigable, or when another skill needs the deep-module vocabulary.
diagnosing-bugs
mattpocock/skills
Diagnosis loop for hard bugs and performance regressions. Use when the user says "diagnose"/"debug this", or reports something broken/throwing/failing/slow.