We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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: 3.3.3 and 3.4.0-dev.20190220 with --strictNullChecks
--strictNullChecks
Search Terms: tuple, union, type deduction, destructuring
Code
function fn(): [null, number] | [string, null] { if (Math.random() > 0.5) { return [null, 2] } return ["Str", null] } // l: string | null (correct) // r: number | null (correct) const [l, r] = fn() if (l === null) { // r: number | null (incorrect) console.log(r + 2) } else { // l: string (correct) // r: number | null (incorrect) console.log(l.toLowerCase(), r === null) }
Expected behavior: No compilation errors. Correct type hints.
Actual behavior: Compilation error:
TS2531: Object is possibly 'null'.
at console.log(r + 2). Incorrect type hints.
console.log(r + 2)
Playground Link: Playground link. Make sure to enable "strictNullChecks".
Related Issues: Did not find anything exactly like this issue.
The text was updated successfully, but these errors were encountered:
This is tracked by this #12184. If you go to the linked issue #28981 the example is more-or-less the same as the one you provide.
Sorry, something went wrong.
Thanks.
No branches or pull requests
TypeScript Version: 3.3.3 and 3.4.0-dev.20190220 with
--strictNullChecks
Search Terms:
tuple, union, type deduction, destructuring
Code
Expected behavior:
No compilation errors. Correct type hints.
Actual behavior:
Compilation error:
at
console.log(r + 2)
. Incorrect type hints.Playground Link:
Playground link. Make sure to enable "strictNullChecks".
Related Issues:
Did not find anything exactly like this issue.
The text was updated successfully, but these errors were encountered: