TypeScript's built-in utility types and how to build custom ones — Partial/Required, Pick/Omit, Readonly/Record, Extract/Exclude, NonNullable/Awaited, ReturnType/Parameters/ConstructorParameters/InstanceType, key remapping with `as` in mapped types, and hand-rolled custom mapped types. Use when picking the right built-in utility type instead of hand-writing one, extracting a function's parameter or return type, filtering a union with Extract/Exclude, or remapping object keys.
68
83%
Does it follow best practices?
Run evals on this skill
Adds up to 20 points to the overall score
View guide
Passed
No findings from the security scan
The standard library of type transformations: which built-in utility type fits a given shape change, and how to build a custom one when none does.
Reach for a built-in utility type before writing a custom one — Partial<T>, Pick<T, K>, ReturnType<typeof fn> and their relatives cover the overwhelming majority of shape transformations, and a hand-rolled equivalent is one more thing to keep in sync with the type it derives from. When a built-in genuinely doesn't fit (a transform needs to recurse into nested objects, or apply a key-by-key rename), build the custom version as a mapped type over the real source type rather than a parallel interface maintained by hand. Combine utilities rather than inventing a new named type for every combination: Partial<Pick<T, K>> is more honest about what it does than a bespoke PartialSubset<T, K> that hides the same composition behind a name.
Use this skill when:
Partial, Required)Pick, Omit)Readonly, Record)Extract, Exclude)null/undefined or unwrapping a Promise (NonNullable, Awaited)as clausePartial, Required, Pick, Omit, Readonly, Record, Extract, Exclude, NonNullable, Awaited, ReturnType, Parameters, ConstructorParameters, InstanceType, ThisParameterType, OmitThisParameter).as clauses, key filtering).typescript-type-system skill.DeepReadonly, DeepPartial) that recurse into nested objects — see deep-readonly.md in the sibling typescript-design-patterns skill.typescript-type-guards skill.Do not use this skill to look up how mapped types or conditional types work mechanically — it assumes that grounding and focuses on the ready-made utilities built from it. For a recursive deep-readonly/deep-partial that walks nested objects, use typescript-design-patterns' deep-readonly.md instead — the utilities here are shallow, one level deep, matching TypeScript's actual built-ins.
npx tsc --noEmitWHY: a hand-written equivalent of Partial<T> or Pick<T, K> doesn't stay in sync when the source type changes, while the built-in always reflects the current shape.
BAD:
interface UserUpdate {
name?: string;
email?: string;
age?: number;
} // duplicates User, optional — drifts if User changesGOOD:
type UserUpdate = Partial<User>;ReturnType<fn> when you mean ReturnType<typeof fn>WHY: fn the value and typeof fn the type are different things in a type position — passing the value's name directly is a type error, not a silent no-op, but it's a common enough slip to call out explicitly.
BAD:
function getUser() { return { id: 1 }; }
type User = ReturnType<getUser>; // error: 'getUser' refers to a valueGOOD:
type User = ReturnType<typeof getUser>;WHY: a name like PartialSubset<T, K> hides Partial<Pick<T, K>> behind an extra layer a reader has to look up, for no gain over writing the composition directly.
BAD:
type PartialSubset<T, K extends keyof T> = Partial<Pick<T, K>>;
// used once, adds an indirection with no new meaningGOOD:
type UserPatch = Partial<Pick<User, "name" | "email">>;| File | Covers |
|---|---|
references/partial-required.md | Partial<T>, Required<T> |
references/pick-omit.md | Pick<T, K>, Omit<T, K> |
references/readonly-record.md | Readonly<T>, Record<K, T> |
references/extract-exclude.md | Extract<T, U>, Exclude<T, U> |
references/nonnullable-awaited.md | NonNullable<T>, Awaited<T> |
references/returntype-parameters.md | ReturnType, Parameters, ConstructorParameters, InstanceType, ThisParameterType, OmitThisParameter |
references/key-remapping.md | Key remapping with as in mapped types |
references/custom-mapped-types.md | Building a custom mapped type when no built-in fits |
a1083f4
If you maintain this skill, you can claim it as your own. Once claimed, you can manage eval scenarios, bundle related skills, attach documentation or rules, and ensure cross-agent compatibility.