Utility types
This is a reference guide for globally-available utility types for common type transformations. You don't need to import these types to use them in your TypeScript programs.
Awaited<Type>
Recursively unwraps a Promise
object.
Partial<Type>
Returns a new version of Type
where all properties are optional.
Required<Type>
Returns a new version of Type
where all properties are required.
Readonly<Type>
Returns a new version of Type
where all properties are set to readonly
. This will produce a type
error
- why freeze an object
Record<Keys, Type>
Produces an object type where keys are of type Keys
and values are of Type
. This utility is often
used to map the properties of a type to another type.
Pick<Type, Keys>
Construct a type by picking Keys
from Type
.
Omit<Type, Keys>
Opposite of Pick
.
Exclude<Type, Members>
Exclude all members of Type
which are assignable to Members
.
Extract<Type, Members>
Only include members of Type
which are assignable to Members
.
NonNullable<Type>
Excludes null
and undefined
from Type
.
Parameters<Type>
Constructs a tuple type from the parameters of the given function.
ConstructorParameters<Type>
Constructs a tuple or array type from the constructor function type, or never
if Type
is not a function.
ReturnType<Type>
Return type of the function.
InstanceType<Type>
Instance type of a constructor function.
NoInfer<Type>
Blocks inference to the type.
ThisParameterType<Type>
Extracts the type of this
, or unknown
if function type has no this
parameter.
OmitThisParameterType<Type>
Omits the this
parameter type.
ThisType<Type>
Does not return a transformed type, but serves as a marker for contextual this
.