utilitypes-ts
    Preparing search index...

    Type Alias StrictOmit<T, K>

    StrictOmit: T extends T ? Omit<T, K> : never

    Strictly omits keys K from each member of a union 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.

    Type Parameters

    • T

      The target type (can be a union)

    • K extends UnionKey<T>

      Keys to remove (must exist in UnionKey<T>)

    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 }