New issue
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
Docs: [prefer-nullish-coalescing] doesn't work with strictNullChecks: false
.
#5748
Comments
This is expected. Use the flag - it's a VERY bad practice to not use it. |
Even if working as intended, which I agrree with, a note should be added to the documentation for the sake of the rule user's. Bad practice indeed, but the flag is there for a reason: sometimes it is unavoidable, at least temporarily. |
True! Marking as accepting PRs for a docs update to mention this on https://typescript-eslint.io/rules/prefer-nullish-coalescing. At least one other rule has a similar limitation. You can probably copy the phrasing from it/them. |
strictNullChecks: false
.strictNullChecks: false
.
We should give it the same treatment as rules like I would say we can do that change without a breaking change because the rule is LITERALLY useless without the option. |
For anybody interested in this as a
We can file a followup issue if you only tackle one and not the other. 🙂 |
Reopening so @cparros can tackle the second part 😄 |
Before You File a Bug Report Please Confirm You Have Done The Following...
Playground Link
https://typescript-eslint.io/play/#ts=4.8.4&sourceType=module&code=DYUwLgBAHgXBDOYBOBLAdgcwgHwgVzQBMQAzdEQgbgCgodcByBmoA&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQAIBcBPABxQGNoBLY-AWhXkoDt8B6Y6RAM0WlqYSNkAC1pkA9gEMkyMswDm6KL2jjokcGAC+ILUA&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylAGYBDVCXTgwAXxCygA
Repro Code
ESLint Config
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 totrue
.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
@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
The text was updated successfully, but these errors were encountered: