Closed as not planned
Closed as not planned
Description
π Search Terms
"optional chaining operator", null check
π Version & Regression Information
- This is the behavior in every version I tried (from 4.4.4 to 5.5.0-dev.20240523)
β― Playground Link
π» Code
interface Foo {
a: string | null;
}
function bar(foo: Foo | null) {
const isNullish = foo?.a == null;
if (isNullish) {
return;
}
// report "Object is possibly 'null'.(2531)" for "foo.a"
console.log(foo.a.toUpperCase());
}
π Actual behavior
Report an error Object is possibly 'null'.(2531)
for foo.a
π Expected behavior
No error is reported
Additional information about the issue
I don't know this behavior is a bug or intended, but based on PR #44730 , I chose 'bug' for this issue.
Metadata
Metadata
Assignees
Labels
No labels