utilitypes-ts
    Preparing search index...

    Type Alias StrictExclude<T, U>

    StrictExclude: Exclude<T, U>

    A stricter version of Exclude that enforces valid exclusion shapes.

    StrictExclude tries to prevent accidentally excluding values that could never exist in T.

    Type Parameters

    • T

      The source union type

    • U extends ExcludeExtractConstraint<T>

      The exclusion type (must conform to T)

    type Result = StrictExclude<"a" | "b" | "c", "a">;
    // ^?
    // "b" | "c"
    type Input =
    | { type: "a"; value: string }
    | { type: "b"; value: number };

    type Result = StrictExclude<Input, { type: "a" }>;
    // ^?
    // { type: "b"; value: number }
    type Input =
    | { a: string }
    | { b: number };

    type Invalid = StrictExclude<
    Input,
    //@ts-expect-error - not compatible with any member of Input
    { c: boolean }
    >;