Skip to content

Instantly share code, notes, and snippets.

@devgioele
Created April 18, 2023 12:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save devgioele/ecd9f9ccc4ba6601366563b56cf137da to your computer and use it in GitHub Desktop.
Save devgioele/ecd9f9ccc4ba6601366563b56cf137da to your computer and use it in GitHub Desktop.
Distributive versions of Pick and Omit
/**
* A version of `Pick` that preserves unions composing `T` by applying `Pick` on each union of `T`.
*/
export type DistributivePick<T, K extends keyof T> = T extends unknown
? Pick<T, K>
: never
/**
* A version of `Omit` that preserves unions composing `T` by applying `Omit` on each union of `T`.
*/
export type DistributiveOmit<T, K extends keyof T> = T extends unknown
? Omit<T, K>
: never
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment