Created
April 18, 2023 12:25
-
-
Save devgioele/ecd9f9ccc4ba6601366563b56cf137da to your computer and use it in GitHub Desktop.
Distributive versions of Pick and Omit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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