Strictly picks keys K from each member of a union T.
K
T
This behaves like Pick, but distributes over unions and only allows keys that actually exist in the union. Passing an invalid key will result in a type error.
Pick
The target type (can be a union)
Keys to pick (must exist in UnionKey<T>)
UnionKey<T>
type Invalid = StrictPick< { a: string }, //@ts-expect-error "b" is not a key of the given type "b">; Copy
type Invalid = StrictPick< { a: string }, //@ts-expect-error "b" is not a key of the given type "b">;
type Result = StrictPick< | { type: "a"; name: string } | { type: "b"; age: number }, "type" | "name">;// ^?// | { type: "a"; name: string; }// | { type: "b"; } Copy
type Result = StrictPick< | { type: "a"; name: string } | { type: "b"; age: number }, "type" | "name">;// ^?// | { type: "a"; name: string; }// | { type: "b"; }
Strictly picks keys
Kfrom each member of a unionT.This behaves like
Pick, but distributes over unions and only allows keys that actually exist in the union. Passing an invalid key will result in a type error.