Skip to content

Instantly share code, notes, and snippets.

@hediet hediet/types.ts
Created Jul 23, 2019

Embed
What would you like to do?
DestructureTuple & DeepSelect
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
You can’t perform that action at this time.