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
Do not emit an error about host possibly being null, since the method exits early if that's the case.
Actual behavior:
Typically when using strictnullchecks Typescript is intelligent enough to understand that when you throw an error from a method based on a type check/guard it narrows the type after the statement. As indicated in this short example:
functiontest(hosts: {whatever: boolean}[]){lethost=hosts.filter((f)=>f.whatever).shift();// Correctly calls out hose as possibly being nullconsole.log(`${host.whatever} selected`);if(!host){thrownewError("Crap!");}// Does not complain here because of the above check/throwconsole.log(`${host.whatever} selected`);}
For some reason when you add the return of the function and use host through a closure it starts complaining.
I'm sure it's the closure, but I don't see how this could error.
The text was updated successfully, but these errors were encountered:
TypeScript Version: 2.1.5
Code
Playground
Expected behavior:
Do not emit an error about
host
possibly being null, since the method exits early if that's the case.Actual behavior:
Typically when using
strictnullchecks
Typescript is intelligent enough to understand that when you throw an error from a method based on a type check/guard it narrows the type after the statement. As indicated in this short example:For some reason when you add the return of the function and use
host
through a closure it starts complaining.I'm sure it's the closure, but I don't see how this could error.
The text was updated successfully, but these errors were encountered: