-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Bug: [prefer-nullish-coalescing] has various bugs around multi-part nullishness checks #10733
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
Comments
We may want to look into sharing logic with |
Indeed I'm interested! |
const test1 = nullOrObject !== foo && bar != null
? nullOrObject
: 42;
|
#10732 fixes your second use case: const test2 = nullOrObject !== foo && null !== null
? nullOrObject
: 42; |
Also to consider: declare let x: { a: string } | null
x?.['a'] ? x.a : 'foo'
x?.a ? x.['a'] : 'foo'
// see `prefer-optional-chain`
x !== null && x.a ? x.a : 'foo' |
I raise you this abomination (false positive) 😁: const a = 'b';
declare let x: { a: string, b: string } | null
x?.a != null ? x[a] : 'foo' Let's spin off a separate issue for that (both would fall under the umbrella that we should potentially use the static member access utils to compare the property being accessed... or maybe we just need to be careful about checking for computed member access in
Hmmmm. I guess yeah this could technically be converted (subject to |
😱 I’ll file an issue.
At first I thought going for the "for free" option, but maybe someone disabling the |
Oh, yeah, that's a good point. I think, since you can't actually fix it without optional chaining (e.g. |
@kirkwaiblinger, did #10861 address everything you had in mind? If so I think the issue can be closed. |
Yep, looks like it! Thanks again for your work on this! ❤ |
Before You File a Bug Report Please Confirm You Have Done The Following...
Playground Link
https://typescript-eslint.io/play/#ts=5.7.2&fileType=.tsx&code=CYUwxgNghgTiAEYD2A7AzgF3igrhCA8jAQEYBW4GAXNnhPAD7wDe8UNmMAligObwBfANwAoEcnRYMITAEZ4AXlr4ipCmCwBCBUpwpQAMx4hg8AGRnl9bUtz4R8eAH4rq8pQfwaAFgBMo8VRMeGlMX0VXYncNeBt4AyQkc0s7ax0rTxdUt3UMTx9-IA&eslintrc=N4KABGBEBOCuA2BTAzpAXGUFvcgAQBcBPABxQGNoBLEggWhXioDsCB6E6RAM0WjuYImyABZ1yAewCGSZORYBzdFADuU6M0jgwAXxA6gA&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylBm3TgwAXxCSgA&tokens=false
Repro Code
ESLint Config
tsconfig
Expected Result
I expect neither test should report
Actual Result
both do
Additional Info
Relates to #10724, but this is an existing bug, not a regression from recent work
cc @OlivierZal if you're interested
The text was updated successfully, but these errors were encountered: