sindresorhus / type-fest

A collection of essential TypeScript types
Creative Commons Zero v1.0 Universal
14.42k stars 548 forks source link

Feature request: `OptionalToExplicit` (transform optional properties to required properties that may be undefined) #953

Open gustavopch opened 2 months ago

gustavopch commented 2 months ago
export type OptionalToExplicit<T> = {
  [P in keyof Required<T>]: Pick<T, P> extends Required<Pick<T, P>>
    ? T[P]
    : T[P] | undefined
}

Consider supporting the "deep" case too.

Adapted from: https://medium.com/terria/typescript-transforming-optional-properties-to-required-properties-that-may-be-undefined-7482cb4e1585

Upvote & Fund

Fund with Polar