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
Argument of type 'Bar' is not assignable to parameter of type 'Foo'.
Types of property 'myvar' are incompatible.
Type 'string | undefined' is not assignable to type 'string'.
Type 'undefined' is not assignable to type 'string'.
π Expected behavior
It should work, as I verified myvar is defined.
Additional information about the issue
No response
The text was updated successfully, but these errors were encountered:
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.
π Search Terms
"undefined is not assignable" assertion
π Version & Regression Information
β― Playground Link
https://www.typescriptlang.org/play?ts=5.1.6#code/JYOwLgpgTgZghgYwgAgGIHt3IN4FgBQAkALYCeAbnFAFzIDOYUoA5gNwEC+BoksiKAISo4CJClQD8tBkxBtOBAjACuIBGGDoQyABZwQAEwA2EDOgAUAfRiZaZgJQ4u+JavWbtewyaFRzAIypaX0c8ImAYZHMAQkCoADoySih7UUIoCDBlKBB2Ii9jU0wAqns85yA
π» Code
π Actual behavior
π Expected behavior
It should work, as I verified
myvar
is defined.Additional information about the issue
No response
The text was updated successfully, but these errors were encountered: