Skip to content
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

[valid-typeof] @typescript-eslint/recommended disables valid-typeof but it shouldn't #3797

Closed
3 tasks done
karoun opened this issue Aug 27, 2021 · 2 comments · Fixed by #5381
Closed
3 tasks done

[valid-typeof] @typescript-eslint/recommended disables valid-typeof but it shouldn't #3797

karoun opened this issue Aug 27, 2021 · 2 comments · Fixed by #5381
Labels
accepting prs Go ahead, send a pull request that resolves this issue breaking change This change will require a new major version to be released package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin recommended-rules Discussion about recommended rule sets
Milestone

Comments

@karoun
Copy link

karoun commented Aug 27, 2021

  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.
  • I have read the FAQ and my problem is not listed.

Repro

{
  "extends": ["plugin:@typescript-eslint/recommended"]
}
typeof window === undefined
typeof window === null

Expected Result

error  Typeof comparisons should be to string literals  valid-typeof

Actual Result

🦗

Additional Info

The @typescript-eslint/recommended ruleset disables the valid-typeof ESLint rule on the basis that it's covered by TypeScript's "This condition will always return 'false'" handling.

However, this is incorrect: TypeScript does not detect this incorrect condition in the case of null and undefined, and so the valid-typeof rule should be re-enabled in the recommended preset.

Versions

package version
@typescript-eslint/eslint-plugin 4.23.0
@typescript-eslint/parser 4.23.0
TypeScript 4.2.4
ESLint 7.26.0
node 12.13.1
@karoun karoun added package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for maintainers to take a look labels Aug 27, 2021
@JounQin
Copy link
Contributor

JounQin commented Aug 30, 2021

A related proof #3635

@bradzacher bradzacher added recommended-rules Discussion about recommended rule sets and removed triage Waiting for maintainers to take a look labels Aug 30, 2021
@bradzacher bradzacher added this to the 5.0.0 milestone Aug 30, 2021
@bradzacher bradzacher added the breaking change This change will require a new major version to be released label Aug 30, 2021
@tanohzana
Copy link
Contributor

I'm working on it!

@bradzacher bradzacher modified the milestones: 5.0.0, 6.0.0 Oct 11, 2021
@JoshuaKGoldberg JoshuaKGoldberg added the accepting prs Go ahead, send a pull request that resolves this issue label Oct 25, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 1, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepting prs Go ahead, send a pull request that resolves this issue breaking change This change will require a new major version to be released package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin recommended-rules Discussion about recommended rule sets
Projects
None yet
5 participants