Skip to content

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

Closed
@karoun

Description

@karoun
  • 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    accepting prsGo ahead, send a pull request that resolves this issuebreaking changeThis change will require a new major version to be releasedpackage: eslint-pluginIssues related to @typescript-eslint/eslint-pluginrecommended-rulesDiscussion about recommended rule sets

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions