
typescript-patterns
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.
- Installs
- 182
- Last 24h
- —
- Trending rank
- —
- Security
- Not audited
Install
Works with every agent the skills CLI supports.
npx skills add https://github.com/oakoss/agent-skills --skill typescript-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-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 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
Exploreagent to find existing patterns in codebase - Type error debugging: Use
Taskagent for multi-step type resolution - Code review: Delegate to
code-reviewerskill for type safety audit
References
- Type utilities (Pick, Omit, Partial, Required, Record, Extract, Exclude, ReturnType, Parameters, Awaited)
- Generics (constraints, inference, default parameters, variance)
- Type guards and narrowing (typeof, instanceof, in, custom guards, assertion functions)
- Discriminated unions (exhaustive checking, never type, tagged unions)
- Conditional types (distributive conditionals, infer keyword, type-level logic)
- Mapped types (key remapping, template literals, modifiers)
- Strict mode patterns (noUncheckedIndexedAccess, exactOptionalPropertyTypes, const assertions, satisfies)
- Module patterns (inline type imports, declaration files, module augmentation, ambient types)
- Modern idioms (eslint-plugin-unicorn patterns, modern array/string/DOM APIs, ES modules)
FAQ
What does the typescript-patterns skill do?
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.
How do I install typescript-patterns?
Run npx skills add https://github.com/oakoss/agent-skills --skill typescript-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-patterns/ (personal) or .claude/skills/typescript-patterns/ (project).
Which AI agents can use typescript-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-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-patterns?
It is published by oakoss in oakoss/agent-skills. It has 182 recorded installs.
More from oakoss/agent-skills
ui-ux-polish
oakoss/agent-skills
Iterative UI/UX polishing workflow for web applications. Use when improving visual polish, refining desktop and mobile UX separately, running iterative enhancement cycles, applying design patterns like glassmorphism or bento grids, or auditing accessibility and WCAG compliance. Use for Stripe-level visual quality, responsive optimization, and design system alignment.
playwright
oakoss/agent-skills
Open the skill to read its SKILL.md instructions.
coolify
oakoss/agent-skills
Coolify self-hosted PaaS for deploying applications, databases, and services via REST API and Git integration. Covers API authentication, deployment triggers, build packs (Nixpacks, Dockerfile, Compose), CI/CD with GitHub Actions webhooks, environment management, and Traefik proxy configuration. Use when deploying apps to Coolify, triggering deployments via API, configuring build packs, setting up GitHub Actions CI/CD pipelines, managing environment variables, or troubleshooting deployment failures.
application-security
oakoss/agent-skills
Application security covering threat modeling (STRIDE), OWASP Top 10 (2025), OWASP API Security Top 10 (2023), secure coding review, authentication/authorization patterns, input validation, encryption, security headers, supply chain security, compliance (GDPR/HIPAA/SOC2/PCI-DSS), and security monitoring. Use when reviewing code for vulnerabilities, implementing auth patterns, securing APIs, configuring security headers, hardening supply chain, preventing injection attacks, or preparing for compliance audits.
find-skills
oakoss/agent-skills
Discovers and installs agent skills from the open ecosystem. Enriches search results with descriptions fetched from skills.sh. Use when a user asks "how do I do X", "find a skill for X", "is there a skill that can...", or wants to extend agent capabilities. Use for skill discovery, skill search, skill install, finding tools.
drizzle-orm
oakoss/agent-skills
Open the skill to read its SKILL.md instructions.
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.