-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Closed
Closed
Copy link
Labels
BugA bug in TypeScriptA bug in TypeScriptFix AvailableA PR has been opened for this issueA PR has been opened for this issue
Milestone
Description
π Search Terms
ts2869
Right operand of ?? is unreachable because the left operand is never nullish.
π Version & Regression Information
Feature introduced in 5.6
reproduced in 5.6.1-rc and v5.7.0-dev.20240826
β― Playground Link
π» Code
function foo(this: Object | undefined) {
return this ?? 0;
}
π Actual behavior
Complains that this
is never nullish.
π Expected behavior
Since this
is explicitly declared as | undefined
, the error should not be shown.
In non-strict mode, this
indeed could not be nullish, but in strict mode it can.
new Function(`"use strict"
function foo() {
console.log(this);
}
foo.apply(undefined)`)()
Additional information about the issue
No response
slavshik and RyanCavanaugh
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptFix AvailableA PR has been opened for this issueA PR has been opened for this issue