Fix #7224, #7441 - Replace TypeFlags.Narrowable by weswigham · Pull Request #7235 · microsoft/TypeScript (original) (raw)
Previously we would only narrow object types, union types, type parameters, and any.
I looked through the history of the area - this check had been here since the inception of type guards (not even user-defined ones), but I'm going to guess that as they evolved nobody ever really noticed that it would need to be removed with the advent of intersection types - given them, we can potentially need to narrow everything (since anything can be intersected with and therefore can have a subtype to narrow to).
I've replaced TypeFlags.Narrowable
with TypeFlags.NotNarrowable
- to make narrowing of a type class opt-out, rather than opt-in, as literally any type can be narrowed to an intersection with that type unless we've expressly choosen to forbid it. I've added Void
to this list, as it's in-line with how we already treat void.
In essence, TypeFlags.NotNarrowable
holds the set of types for which this function:
declare function isTagged(x: T): x is (T & {__tagged: any});
does not narrow as expected, which, as far as I can tell, should only be void
.