We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
no-instanceof-builtin-object
instanceof operator in JavaScript has some limitations.
instanceof
To detect the type of a variable, we should encourage user to use:
typeof
typeof foo === 'string' // detect whether foo is string
node:util/types
import {isNumberObject, isMap} from 'node:util/types'; isNumberObject(new Number(123)) // true isNumberObject(123) // false isMap(new Map()) // true
@sindresorhus/is
import is from '@sindresorhus/is'; is(new Map()) === 'Map' // true
Therefore, builtin objects like Map/Promise/Error can be detected by typeof, node:util/types and @sindresorhus/is. Should not use instanceof.
Map
Promise
Error
Rule no-instanceof-array can be removed if this rule is implemented.
no-instanceof-array
foo instanceof Array foo instanceof Map foo instanceof Promise
import types from 'node:util/types' Array.isArray(foo) types.isMap(foo) types.isPromise(foo)
import is from '@sindresorhus/is' is(foo) === 'Array' is(foo) === 'Map' is(foo) === 'Promise'
No response
The text was updated successfully, but these errors were encountered:
no-instanceof-function
No branches or pull requests
Description
instanceof
operator in JavaScript has some limitations.To detect the type of a variable, we should encourage user to use:
typeof
operatornode:util/types
module (for Node)@sindresorhus/is
module (for browser)Therefore, builtin objects like
Map
/Promise
/Error
can be detected bytypeof
,node:util/types
and@sindresorhus/is
. Should not useinstanceof
.Rule
no-instanceof-array
can be removed if this rule is implemented.Fail
Pass
Proposed rule name
no-instanceof-builtin-object
Additional Info
No response
The text was updated successfully, but these errors were encountered: