Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork2.8k
Labels
accepting prsGo ahead, send a pull request that resolves this issuedocumentationDocumentation ("docs") that needs adding/updatingfix: strictNullChecksissues that were fixed by turning on strictNullChecksgood first issueGood for newcomerspackage: eslint-pluginIssues related to @typescript-eslint/eslint-plugin
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 havesearched for related issues and found none that matched my issue.
- I haveread the FAQ and my problem is not listed.
Playground Link
Repro Code
letx:string|undefined;x||'';
ESLint Config
module.exports={parser:"@typescript-eslint/parser","rules":{"@typescript-eslint/prefer-nullish-coalescing":"error"}};
tsconfig
{"compilerOptions": {"strictNullChecks":false }}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 ifstrictNullChecks is changed totrue.
This makes sense becausestrictNullChecks: 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 |
Metadata
Metadata
Assignees
Labels
accepting prsGo ahead, send a pull request that resolves this issuedocumentationDocumentation ("docs") that needs adding/updatingfix: strictNullChecksissues that were fixed by turning on strictNullChecksgood first issueGood for newcomerspackage: eslint-pluginIssues related to @typescript-eslint/eslint-plugin