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