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
Search Terms: let inference inferred union type guard narrow defer deferred
Code
interfaceSuccess{success: true;response: object;}interfaceError{success: false;error: object;}functionrequest(): Success|Error{returnnullasany;}// This does not work:letr;r=request();// This does:// let r = request();// The type information give on hover for `r` here is the same in both cases: `Success | Error`.r;if(r.success){r.response;}
Expected behavior:r.response is accessible within the block guarded by r.success. Changing the declaration of r to a single line let r = request(); has no effect.
Actual behavior:r is not type-narrowed, so r.response is not accessible. Changing the declaration to a single line resolves the issue.
TypeScript Version: 3.6.3
Search Terms: let inference inferred union type guard narrow defer deferred
Code
Expected behavior:
r.response
is accessible within the block guarded byr.success
. Changing the declaration ofr
to a single linelet r = request();
has no effect.Actual behavior:
r
is not type-narrowed, sor.response
is not accessible. Changing the declaration to a single line resolves the issue.Playground Link: https://www.typescriptlang.org/play/index.html#code/JYOwLgpgTgZghgYwgAgMoFcFIM7eQbwChkTltMdsAuZMKdCAbmNKgmwAcB7EbCGrgCMAVhARhmAX0KFQkWIhQBRKFC5QCLEuSztqyeABs+zUsmhqoAkWImFphGOhDjgPZGwCODbGAAUAJQ0GLq4yAA+yCqWmmZsYOhQIMgg6IaGyHB4cCAAnlIyAPSFyAAqABbAeAAmXOwpXGDIAO7qANZUhIYQTVDMGgC8HhDe7P4BzITFZZU1ddRTJd29yENePuOT0xUoYLkcKKAw6gC2cGBuyQDmwABuKO7lXPcaxxoABlDvyOXQh3hgX5kOAnQ7JQSNcrIBBZdg0d4hSgRKKqdTvAB0hD6MmAMGQfig6J0lACsVY6LYnB4JnsQA
Related Issues:
The text was updated successfully, but these errors were encountered: