You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Your described actual behaviour is wrong. The actual behaviour is what you describe in expected behaviour. The type of input.yis narrowed to string, it is notstring | undefined anymore.
You expect the type of input to be narrowed to API, but that's not supported.
Type guards do not propagate type narrowings to parent objects. The narrowing is only applied upon access of the narrowed property which is why the destructing function works, but the reference function does not. Narrowing the parent would involve synthesizing new types which would be expensive. More detail in this comment.
Bug Report
I wrote a helper type to making some fields of object optional. But I got the following error in type narrowing.
π Search Terms
type narrowing, optionalize
π Version & Regression Information
β― Playground Link
Playground link with relevant code
π» Code
π Actual behavior
input.y
isstring | undefined
π Expected behavior
I expected
input.y
to bestring
The text was updated successfully, but these errors were encountered: