Skip to content

Enforce comparing typeof expressions against string literals #629

@feross

Description

@feross

I propose adding { "requireStringLiterals": true } to the valid-typeof rule that we already enforce.

This requires typeof expressions to only be compared to string literals, and disallows comparisons to any other value.

Examples of incorrect code:

typeof foo === undefined
typeof bar == Object
typeof baz === 'strnig'
typeof qux === 'some invalid type'
typeof baz === anotherVariable
typeof foo == 5
typeof bar === typeof qux

Examples of correct code:

typeof foo === 'undefined'
typeof bar == 'object'
typeof baz === 'string'

http://eslint.org/docs/rules/valid-typeof

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Done

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions