The most used utility types fall into three groups: reshaping objects, filtering unions, and reading function types.
For reshaping objects:
Partial<T>makes every property optional. It is handy for update payloads, where you send only the changed fields.Required<T>makes every property required.Readonly<T>marks every property readonly.Pick<T, K>keeps only some keys.Omit<T, K>removes some keys.Record<K, V>builds an object type with keysKand valuesV.
For unions:
Exclude<U, X>removes the members that can be assigned toX.Extract<U, X>keeps only those members.NonNullable<T>removesnullandundefined.
For functions and promises:
ReturnType<F>reads a function's return type.Parameters<F>reads a function's parameter types as a tuple.Awaited<T>unwraps a promise to its resolved value.
These let you build types from existing code instead of writing them twice.
Partial,RequiredandReadonlychange the modifiers of every property.PickandOmitchoose which keys to keep, andRecordbuilds key-value object types.Exclude,ExtractandNonNullablework on union types.ReturnType,ParametersandAwaitedbuild types from functions and promises.
Read more