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
Currently, even if a type is narrowed down to nothing, we still consider control flow errors in those branches even though you might just be handling error cases:
// Error: Not all code paths return a value.functionfoo(x: string|number){if(typeofx==="string"){returntrue;}elseif(typeofx==="number"){returnfalse;}fail("Unexhaustive!");}functionfail(message: string){throwmessage;}
Similarly, if you add a type annotation, you'll get an error.
// Error: Function lacks ending return statement but return type lacks 'undefined'functionfoo(x: string|number): boolean{if(typeofx==="string"){returntrue;}elseif(typeofx==="number"){returnfalse;}fail("Unexhaustive!");}functionfail(message: string){throwmessage;}