# Typescript Advanced Types

> Use when: model complex APIs with discriminated unions, conditional, and template literal types.

- Skill: `kimtth/typescript-advanced-types` (Agent Skill)
- Install (CLI): `npx skillmds@latest add kimtth/typescript-advanced-types`
- Raw SKILL.md: https://api.skillmd.com/api/skills/kimtth/typescript-advanced-types/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: AI & ML
- Author: kimtth (https://skillmd.com/u/kimtth)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/kimtth/typescript-advanced-types

---


Goal: types that make illegal states unrepresentable without ceremony.

Use for:
- modeling variant data and state machines
- typing flexible component or function APIs
- replacing `any` and unsafe casts with precise types

Workflow:
1. Model variants as a discriminated union with a tag field.
2. Narrow with the tag so each branch is fully typed.
3. Use conditional types to derive types from inputs.
4. Use template literal types for structured string keys.
5. Reach for utility types (Pick, Omit, Record, ReturnType) first.
6. Add generic constraints to keep inference helpful.

Patterns:
- discriminated unions over optional-flag soup
- `infer` to extract types from structures
- mapped + template literal types for key transforms
- `satisfies` to check without widening

Rules:
- prefer inference; annotate only where it adds safety or clarity
- avoid `any`; use `unknown` then narrow
- do not over-engineer types past what the API needs
- a type that confuses readers is a liability, not a win

