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 #16476

Open
humandetail opened this issue Sep 22, 2022 · 0 comments
Open

956 - DeepPick #16476

humandetail opened this issue Sep 22, 2022 · 0 comments
Labels
956 answer Share answers/solutions to a question en in English

Comments

@humandetail
Copy link
Contributor

// your answers

type Get<T, K extends string> = K extends `${infer Key}.${infer R}`
  ? Key extends keyof T
    ? { [P in keyof T as P extends Key ? P : never]: Get<T[Key], R> }
    : never
  : K extends keyof T
    ? { [P in keyof T as P extends K ? P : never ]: T[K] }
    : never

/**
 * UnionToFunc<1 | 2> => ((arg: 1) => void | (arg: 2) => void)
 */
 type UnionToFunc<T> = T extends unknown ? (arg: T) => void : never

 /**
  * UnionToIntersection<1 | 2> = 1 & 2
  */
 type UnionToIntersection<U> = UnionToFunc<U> extends (arg: infer Arg) => void
   ? Arg
   : never

type DeepPick<T, K extends string> = UnionToIntersection<Get<T, K>>
@humandetail humandetail added answer Share answers/solutions to a question en in English labels Sep 22, 2022
@github-actions github-actions bot added the 956 label Sep 22, 2022
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