Closed
Description
Possibly this lies between being a Bug and being a blind spot in the documentation (Handbook, in this case), but I can't see any indication in the specification of Exclude
that it only works to exclude individual types from a union type. I might guess that this is the case from the provided examples, but probably that's not the intent of the documentation.
Here is a minimal example of what I'm referring to:
Bug Report
🔎 Search Terms
- exclude utility type
- exclude from string
- exclude from type
🕗 Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about bugs that are not bugs_
- I was unable to test this on prior versions because time
⏯ Playground Link
Playground link with relevant code
💻 Code
type T0 = Exclude< string, "a">;
// ^? (== string)
type T1 = Exclude< "a" | "b", "a">;
// ^?
let a0 : T0 = "a" // should be excluded?
let a1 : T1 = "a" // works ( ie, the assignment does not work. The _exclude_ works )
🙁 Actual behavior
Exclude
did not exclude the supplied ExcludedUnion
("a"
) from string
.
🙂 Expected behavior
Exclude
excludes "a"
from the defined type. From the handbook:
Exclude<Type, ExcludedUnion>
Constructs a type by excluding from Type all union members that are assignable to ExcludedUnion