Skip to content

Instantly share code, notes, and snippets.

@hediet
Created July 23, 2019 10:49
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 hediet/3ac78968f26b40a33ca1bfe27474f919 to your computer and use it in GitHub Desktop.
Save hediet/3ac78968f26b40a33ca1bfe27474f919 to your computer and use it in GitHub Desktop.
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