-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Bug: [strict-boolean-expressions] allowNullableBoolean - support array predicate functions #10688
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
This is useful for logic expressions that use null coalescing, e.g.:
|
Just noting for conversation - this isn't a bug about the |
Thanks, @kirkwaiblinger, that makes sense! Could you clarify what you mean by
I'm not sure I follow. |
Oh, yeah, basically I'm just saying: const arrayOfNullables = [null, "not null"];
const nonNullablesBad = arrayOfNullables.filter(x => x);
// TS ERROR - x is possibly null
nonNullablesBad.forEach(x => console.log(x.toLowerCase()));
const nonNullablesGood = arrayOfNullables.filter(x => x != null);
// works!
nonNullablesGood.forEach(x => console.log(x.toLowerCase())); For further reading on inferred type predicates, see the TS 5.5 release notes. Also related, #9764 So, IMO there's additional benefit in TS to using an actual boolean return in array predicate callbacks compared to the ordinary stylistic reasons for using strict-boolean-expressions. |
Thanks! I was not familiar with inferred type predicates, makes sense. |
Uh oh!
There was an error while loading. Please reload this page.
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=LAKAxg9gdgzgLgAgIYC4EAoCuUAmBTAMwEso8cEAfBAIwggBs8kpKEpN76BKAbQF0EAXgQ84AJ0x4ANAmz5ipHDPac%2BAblBIAdDAgBbPOnQAPLkIB8CUxpChIsRNTTpaDJiyoru-ISPGTlDnp1UGodfUMTM0FLa1A7aHgEMGdXRmZWOUISMl4BYVEJaVlcbMUQ8HCDI1MLKy4bBIcEHFS6dKg830LJPlAcKsjamPqgA&eslintrc=N4KABGBEBOCuA2BTAzpAXGUFs6gAQBcBPABxQGNoBLEggWhXioDsCB6ZA68%2BgIwHt%2BSAIbMGADxLQUyKv2aoMAbXC4IkRNGj9okADSq1OYFGHx4-AO4A5BPGG8kAIUEjm6MF1iIwAX0NGALqq-r5AA&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylBm3TgwAXxCSgA&tokens=false
Repro Code
ESLint Config
tsconfig
Expected Result
I expected there to be no errors.
Actual Result
It seems like the array functions doesn't respect the "allowNullableBoolean" option
Additional Info
Probably introduced in this PR #10106
The text was updated successfully, but these errors were encountered: