diff --git a/docs/rules/valid-typeof.md b/docs/rules/valid-typeof.md index 2ce02b4906b..b1884a874a9 100644 --- a/docs/rules/valid-typeof.md +++ b/docs/rules/valid-typeof.md @@ -1,6 +1,6 @@ # enforce comparing `typeof` expressions against valid strings (valid-typeof) -For a vast majority of use cases, the result of the `typeof` operator is one of the following string literals: `"undefined"`, `"object"`, `"boolean"`, `"number"`, `"string"`, `"function"` and `"symbol"`. It is usually a typing mistake to compare the result of a `typeof` operator to other string literals. +For a vast majority of use cases, the result of the `typeof` operator is one of the following string literals: `"undefined"`, `"object"`, `"boolean"`, `"number"`, `"string"`, `"function"`, `"symbol"`, and `"bigint"`. It is usually a typing mistake to compare the result of a `typeof` operator to other string literals. ## Rule Details @@ -57,3 +57,7 @@ typeof bar === typeof qux ## When Not To Use It You may want to turn this rule off if you will be using the `typeof` operator on host objects. + +## Further Reading + +* [MDN: `typeof` documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeof) diff --git a/lib/rules/valid-typeof.js b/lib/rules/valid-typeof.js index 16b2a47d371..a0f20f74d0e 100644 --- a/lib/rules/valid-typeof.js +++ b/lib/rules/valid-typeof.js @@ -39,7 +39,7 @@ module.exports = { create(context) { - const VALID_TYPES = ["symbol", "undefined", "object", "boolean", "number", "string", "function"], + const VALID_TYPES = ["symbol", "undefined", "object", "boolean", "number", "string", "function", "bigint"], OPERATORS = ["==", "===", "!=", "!=="]; const requireStringLiterals = context.options[0] && context.options[0].requireStringLiterals; diff --git a/tests/lib/rules/valid-typeof.js b/tests/lib/rules/valid-typeof.js index 0033a4f8abd..cd28088a0ed 100644 --- a/tests/lib/rules/valid-typeof.js +++ b/tests/lib/rules/valid-typeof.js @@ -26,6 +26,7 @@ ruleTester.run("valid-typeof", rule, { "typeof foo === 'undefined'", "typeof foo === 'boolean'", "typeof foo === 'number'", + "typeof foo === 'bigint'", "'string' === typeof foo", "'object' === typeof foo", "'function' === typeof foo",