type ObjectPick<T, K, BailType> = { [Key in K as PropValue<T, Key> extends never ? never : Key]: PropValue<T, Key> } extends infer Result ? IsNonNullish<Result> extends true ? BailType : Result : never;Extended TypeScript `Pick` to pick K from T.
| Type Parameter | Default type | Description |
|---|---|---|
|
|
‐ |
The target type. |
|
|
‐ |
The keys of |
|
|
|
‐ |
Set of properties whose keys are in the union K.
type Obj = { a: string; b: string };
// { a: string; }
type Picked = ObjectPick<Obj, 'a'>;