We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TypeScript Version: 4.1.2 (strict)
Search Terms: conjunction falsy narrowing
Code
function foo( k: string | undefined, i: string ) : string { const g = k && i; if( g ) { return k; } return ""; } function bar( k: string | undefined, i: string ) : string { if( k && i ) { return k; } return ""; }
Expected behavior: I would expect both of these to typecheck in strict - in both cases k is only returned if it is non-falsy.
Actual behavior: foo() fails to typecheck with the following error:
test.ts:4:8 - error TS2322: Type 'string | undefined' is not assignable to type 'string'. Type 'undefined' is not assignable to type 'string'.
however, bar() does pass typechecking.
Playground Link:
Related Issues:
The text was updated successfully, but these errors were encountered:
Duplicate of #12184.
Sorry, something went wrong.
Successfully merging a pull request may close this issue.
TypeScript Version: 4.1.2 (strict)
Search Terms: conjunction falsy narrowing
Code
Expected behavior:
I would expect both of these to typecheck in strict - in both cases k is only returned if it is non-falsy.
Actual behavior:
foo() fails to typecheck with the following error:
however, bar() does pass typechecking.
Playground Link:
Related Issues:
The text was updated successfully, but these errors were encountered: