TypeScript 7 reference · 16 entries
TypeScript Utility Types
TypeScript's built-in utility types: Partial, Required, Readonly, Pick, Omit, Record, Exclude, Extract, ReturnType, Awaited and more, with examples that are type-checked and run.
Utility types transform other types, so you describe a shape once and derive the rest. They exist only at compile
time: they don't change your JavaScript output. Lines marked // @ts-expect-error show what the compiler rejects.
| Name | Description | Since |
|---|---|---|
Partial<Type> |
Make every property of a type optional. Useful for update functions that accept only the fields that change. | 2.1 |
Required<Type> |
Make every property of a type required, removing the ? from optional properties. The opposite of Partial. | 2.1 |
Readonly<Type> |
Make every property of a type read-only, so the compiler rejects assignments to them after creation. | 2.1 |
Pick<Type, Keys> |
Build a type from just some properties of another type. Handy for API responses and props that need a subset. | 2.1 |
Omit<Type, Keys> |
Build a type with all properties of another type except the ones you list. The opposite of Pick. | 3.5 |
Record<Keys, Type> |
Build an object type whose keys come from Keys and whose values all have Type. Great for lookup tables. | 2.1 |
Exclude<UnionType, ExcludedMembers> |
Remove members from a union type. Exclude<'a' | 'b' | 'c', 'a'> is 'b' | 'c'. | 2.8 |
Extract<Type, Union> |
Keep only the members of a union that are assignable to another type. The opposite of Exclude. | 2.8 |
NonNullable<Type> |
Remove null and undefined from a type, for values you've already checked or that can never be missing. | 2.8 |
ReturnType<Type> |
Get the return type of a function type, so other code can reuse it without repeating it. | 2.8 |
Parameters<Type> |
Get a function's parameter types as a tuple, useful for wrappers that pass arguments through. | 3.1 |
Awaited<Type> |
Unwrap the value type of a Promise (recursively), like what await gives you. Awaited<Promise<number>> is number. | 4.5 |
InstanceType<Type> |
Get the type of the object a class constructor creates, from the constructor's type. | 2.8 |
NoInfer<Type> |
Stop TypeScript from inferring a type parameter from a particular argument, so other arguments decide it. | 5.4 |
Uppercase<StringType> |
Turn a string literal type into upper case at the type level: Uppercase<'get'> is 'GET'. | 4.1 |
Capitalize<StringType> |
Upper-case the first character of a string literal type: Capitalize<'click'> is 'Click'. Used to build names like onClick. | 4.1 |