Skip to content

956 - DeepPick #3294

Open
Open

Description

@jiangshanmeta
type DeepPick<T extends Record<string,any>, U extends string> = (U extends string? 
  U extends `${infer F}.${infer R}`?
    (arg:{
      [K in F]:DeepPick<T[F],R>
    })=>void
    :U extends keyof T?
      (arg:Pick<T,U>)=>void
      :(arg:unknown)=>void
  :never
  
  ) extends (arg:infer Z)=>void? Z:never;

Activity

  1. added
    answer
    en
    on Sep 15, 2021
  2. 2083335157 commented on Nov 17, 2024

    @2083335157

    Nice, I tried to simplify it.

    type DeepPick<T, U extends string> = (
      U extends `${infer F}.${infer R}`
        ? (arg: { [K in F]: DeepPick<T[F & keyof T], R> }) => void
        : U extends keyof T
          ? (arg: Pick<T,U>) => void
          : (arg: unknown) => void
    ) extends (arg: infer Z) => void ? Z : never
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    956answeren

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions