Bug: [prefer-nullish-coalescing] Should not report on false | undefined values by default #11092
Open
4 tasks done
Labels
bug
Something isn't working
package: eslint-plugin
Issues related to @typescript-eslint/eslint-plugin
triage
Waiting for team members to take a look
Before You File a Bug Report Please Confirm You Have Done The Following...
Playground Link
https://typescript-eslint.io/play/#ts=5.8.2&fileType=.ts&code=CYUwxgNghgTiAEYD2A7AzgF3gWygTwCMQAueAcijPgB9yCyBuAKFElgWXSwDMoIICUMAGtSAbTJgyAXWatoceNwCuKMBgCWqRHCgYQANT7KQaABQBKUphgaUAczHSa8VaG52QwZkxVrN2sjYAA7K%2BgDKGLYO5lbwNnaOzgDeTPCIqJjwdvow2F4aeggAvDj4RPDFVeSU8ABkdTogRUYQJrE%2B6ZxZAG7GJdkoufnAhfo0tLz8giKd8HAYyjAo8H1tIMwAvkxAA&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQAIBcBPABxQGNoBLY-AWhXkoDt8B6Y6RAM0WlqYSNkAC1pkA9gEMkyMswDm6KL2jjokcGAC%2BILUA&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylBm3TgwAXxCSgA&tokens=false
Repro Code
ESLint Config
tsconfig
Expected Result
intermediate
isfalse | string[] | undefined
and its parent function returnsstring[]
. The||
is the right operator to use to makevalue
astring[]
, not astring[] | false
.Actual Result
Additional Info
Related: #7055, #10356, and probably others, searching gives a lot of false positive results...
#10356 notes that this gets suggested a good amount. I personally was surprised to re-discover that the default behavior of the rule is to report in a way that is sometimes incorrect/unnecessary.
Proposal: I think we should switch the rule to ignore
false | undefined | (always-truthy)
s by default.💖
The text was updated successfully, but these errors were encountered: