Open AlexPaven opened 3 months ago
According to the source code, it's deliberate (link):
// Constituent type predicates must all have matching kinds. We don't create composite type predicates for assertions.
If it's not supported it would be nice if it produced an error similar to #33622 instead of just silently failing.
@RyanCavanaugh could you clarify what is the bug here? should it work or should it error in a visible way like @jcalz is suggesting? I think the latter but it would be great to have confirmation
π Search Terms
narrowing, assertion function
π Version & Regression Information
β― Playground Link
https://tsplay.dev/Wv3DYw
π» Code
π Actual behavior
Type is not narrowed after method call
π Expected behavior
I expected the type to be narrowed after method call since it is narrowed within other methods or when using a function external to the type.
Additional information about the issue
https://stackoverflow.com/questions/78879014/typescript-type-assertion-does-not-narrow-class-instance-from-union