-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
[strict-boolean-expressions] False positive when using union types #2894
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
Right now this is "working as intended"
With your options - you've specified that you don't care about the Which begs the question: "is The question is - how should we handle this? |
Yeah, I definitely come down on the user's side on this one 😉 Mainly because given the settings, if the value were either of the two truthy states it would be allowed, so I would want the combination to be allowed. But if extra strictness is desire/required, maybe have a |
It works fine in this case. This rule is all about being explicit. You should write your condition as something like |
This comment was marked as resolved.
This comment was marked as resolved.
Try using
At Facebook the entire codebase exclusively uses |
Thanks, that's interesting; so it sounds like you don't enforce triple-equals in TS. That makes sense; I hadn't even considered that |
On the contrary - See the end of this section: https://eslint.org/docs/rules/eqeqeq#always
|
Wow, that is 1000x better than what I was doing, thank you! Edit: |
I believe this issue can be closed |
Indeed. I think the rule is working as intended, as previously mentioned. There are two falsy cases in type One could make an argument that the combination of Marking this as working-as-intended because of all that, and that there's been very little activity on this issue in the almost 2 years it's been open. Feel free to post back or make a new issue if you think this is incorrect! Thanks all! |
Uh oh!
There was an error while loading. Please reload this page.
Repro
tsconfig.json
Expected Result
No error on the
if (value) {
lineActual Result
"Unexpected value in conditional. A boolean expression is required." on the
if (value) {
lineVersions
@typescript-eslint/eslint-plugin
4.10.0
@typescript-eslint/parser
4.10.0
TypeScript
4.0.5
ESLint
7.16.0
node
12.16.2
The text was updated successfully, but these errors were encountered: