A stricter version of Exclude that enforces valid exclusion shapes.
Exclude
StrictExclude tries to prevent accidentally excluding values that could never exist in T.
StrictExclude
T
The source union type
The exclusion type (must conform to T)
type Result = StrictExclude<"a" | "b" | "c", "a">;// ^?// "b" | "c" Copy
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 } Copy
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 }>; Copy
type Input = | { a: string } | { b: number };type Invalid = StrictExclude< Input, //@ts-expect-error - not compatible with any member of Input { c: boolean }>;
A stricter version of
Excludethat enforces valid exclusion shapes.StrictExcludetries to prevent accidentally excluding values that could never exist inT.