TypeScript Utility Types
TypeScript provides several global utility types to facilitate common type transformations.
Property Modifiers
Partial<T>: Constructs a type with all properties ofTset to optional.Required<T>: Constructs a type with all properties ofTset to required (opposite ofPartial).Readonly<T>: Constructs a type with all properties ofTset toreadonly.
Subset and Mapping
Record<K, T>: Constructs an object type whose property keys areKand whose property values areT.Pick<T, K>: Constructs a type by picking the set of propertiesK(string literal or union of string literals) fromT.Omit<T, K>: Constructs a type by picking all properties fromTand then removingK.
Union Manipulation
Exclude<T, U>: Excludes fromTthose types that are assignable toU.Extract<T, U>: Extracts fromTthose types that are assignable toU.NonNullable<T>: ExcludesnullandundefinedfromT.
Function and Class Types
Parameters<T>: Obtains the parameters of a function type in a tuple.ReturnType<T>: Obtains the return type of a function type.ConstructorParameters<T>: Obtains the parameters of a constructor function type in a tuple.InstanceType<T>: Obtains the instance type of a constructor function type.
Advanced
Awaited<T>: Models operations likeawaitinasyncfunctions, or the.then()method onPromises.
References
- Source:
00_Raw/typescript-handbook.md - typescript-moc
- typescript-generics
- typescript-conditional-types
- agent-note-conventions (Modeling metadata constraints)
- typescript-objects