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
[new rule] Disallow !?? (Non-null + nullish) #2853
Comments
Seems like a logical cousin to |
You're right, My example is covered by that rule: This issue can be closed as far as I'm concerned. |
It would be appreciated if you can paste the code (example) caused false-positive in your project. Just at assigning array element to variable? |
There's no false positive. My example matches your example except it uses the same API I used initially. |
Thanks for pointing that out @ypresto! For reference this could also be handled via {
"no-restricted-syntax": [
"error",
{
"selector": "LogicalExpression[operator='??'] > TSNonNullExpression.left",
"message": "Why the heck are you non-nulling a nullish-coalesce?"
},
],
} (dump the config into here to see it working!) Closing as there are multiple ways to achieve this without a new rule. For reference - |
Oh maybe you were referring to this: I didn't personally encounter the issue; I said "my preset" but I meant "the preset I use" |
!
in TypeScript (non-null assertion operator) cancels the null type and??
(nullish coalescing operator) actually handles it. The first one is redundant.This is a suggestion for a new rule:
Fail
Pass
The text was updated successfully, but these errors were encountered: