Created
July 23, 2019 10:49
-
-
Save hediet/3ac78968f26b40a33ca1bfe27474f919 to your computer and use it in GitHub Desktop.
DestructureTuple & DeepSelect
This file contains hidden or 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
export type DestructureTuple<T extends any[]> = T extends [] | |
? false | |
: ((...tuple: T) => void) extends (( | |
first: infer TFirst, | |
...rest: infer TRest | |
) => void) | |
? { first: TFirst; rest: TRest } | |
: false; | |
export type DeepSelect<TObj, TPath extends any[]> = DestructureTuple< | |
TPath | |
> extends { | |
first: infer TFirst; | |
rest: infer TRest; | |
} | |
? { | |
[TKey in TFirst & keyof TObj]: DeepSelect< | |
TObj[TKey], | |
TRest extends any[] ? TRest : never | |
> | |
} | |
: TObj; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment