Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

956 - DeepPick #29843

Open
tclxshunquan-wang opened this issue Sep 1, 2023 · 0 comments
Open

956 - DeepPick #29843

tclxshunquan-wang opened this issue Sep 1, 2023 · 0 comments
Labels
956 answer Share answers/solutions to a question en in English

Comments

@tclxshunquan-wang
Copy link

type UnionToIntersection<T> = (T extends any ? (args: T) => any : never) extends (args: infer R) => any ? R : never;

type LastInUnion<T> = UnionToIntersection<(T extends any ? (arg: T) => any : never)> extends (arg: infer R) => any ? R : never;

type UnionToTuple<T, U = T> = [T] extends [never] ? [] : [LastInUnion<T>, ...UnionToTuple<Exclude<U, LastInUnion<T>>>];

type PickOne<T, K, Last = T> = K extends '' ? unknown : K extends `${infer A extends string}.${infer B}` ? (A extends keyof T ? {
  [key in A]: PickOne<T[key], B, T[key]>
} : never) : K extends keyof Last ? {
  [K1 in K]: Last[K1]
} : Last

type Tuple<T> = UnionToTuple<T>

type PickLoop<T, K extends any[], U = unknown> = K extends [infer A, ...infer B] ? PickLoop<T, B, PickOne<T, A> & U> : U

type DeepPick<T, K> = PickLoop<T, Tuple<K>>
@tclxshunquan-wang tclxshunquan-wang added answer Share answers/solutions to a question en in English labels Sep 1, 2023
@github-actions github-actions bot added the 956 label Sep 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
956 answer Share answers/solutions to a question en in English
Projects
None yet
Development

No branches or pull requests

1 participant