Skip to content

Instantly share code, notes, and snippets.

@yurypaleev
yurypaleev / path.ts
Last active May 17, 2021 10:13
Type Path returns all possible variants of the key for the function lodash.get
type ValueOf<T> = T[keyof T];
type ArrayPath<T> =
T extends Array<unknown>
? ArrayPath<Omit<T, keyof []>>
: T extends object
? ValueOf<{
[K in keyof T]: [K] | [K, ...ArrayPath<T[K]>];
}>
: never;