-
-
Save dlaub3/823365161ae6e8437a967611682e573f to your computer and use it in GitHub Desktop.
TS Utilities
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
// Extract the desired values from a union of objects | |
type ExtractUnionValues<T extends {}, ExcludProps extends string = never> = T extends Extract<T, { [K in infer P]: any }> ? T[Exclude<P, ExcludProps>] : never | |
type PickUnionValues<T extends {}, Props extends string = never> = T extends Extract<T, { [K in infer P]: any }> ? T[Extract<P, Props>] : never | |
// alternative implementation | |
type ExtractUnionValues<T extends {}, ExcludedProps extends string = never> = T extends {} ? Omit<T, ExcludedProps>[keyof Omit<T, ExcludedProps>]: never | |
type PickUnionValues<T extends {}, Props extends string = never> = T extends {} ? Pick<T, Extract<keyof T, Props>>[keyof Pick<T, Extract<keyof T, Props>>]: never |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment