Description
Before You File a Bug Report Please Confirm You Have Done The Following...
- I have tried restarting my IDE and the issue persists.
- I have updated to the latest version of the packages.
- I have searched for related issues and found none that matched my issue.
- I have read the FAQ and my problem is not listed.
Playground Link
Repro Code
let x: string | undefined;
x || '';
ESLint Config
module.exports = {
parser: "@typescript-eslint/parser",
"rules": {
"@typescript-eslint/prefer-nullish-coalescing": "error"
}
};
tsconfig
Expected Result
An error should be reporting for the ||
, which should be replaced with ??
.
Actual Result
No error is reported.
Additional Info
The same rule works if strictNullChecks
is changed to true
.
This makes sense because strictNullChecks: false
essentially erases | null
and | undefined
from all types.
Ideally the rule should work anyway, assuming all types to be nullable. If that's not possible, a note should be added to the documentation so people do not spend a whole afternoon trying to understand why the rule doesn't work, as I did.
Versions
package | version |
---|---|
@typescript-eslint/eslint-plugin |
5.39.0 |
@typescript-eslint/parser |
5.39.0 |
TypeScript |
4.4.4 |
ESLint |
7.32.0 |
node |
12.22.6 |