Skip to content

Commit e4ab053

Browse files
cjihrigilyavolodin
authored andcommitted
Update: support "bigint" in valid-typeof rule (#11802)
* Update: support "bigint" in valid-typeof rule BigInt just moved to Stage 4, so add support for it to the valid-typeof rule. * Docs: add Further Reading to valid-typeof rule This commit adds a Further Reading section to the valid-typeof rule documentation.
1 parent e0fafc8 commit e4ab053

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

docs/rules/valid-typeof.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# enforce comparing `typeof` expressions against valid strings (valid-typeof)
22

3-
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.
3+
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.
44

55
## Rule Details
66

@@ -57,3 +57,7 @@ typeof bar === typeof qux
5757
## When Not To Use It
5858

5959
You may want to turn this rule off if you will be using the `typeof` operator on host objects.
60+
61+
## Further Reading
62+
63+
* [MDN: `typeof` documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeof)

lib/rules/valid-typeof.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ module.exports = {
3939

4040
create(context) {
4141

42-
const VALID_TYPES = ["symbol", "undefined", "object", "boolean", "number", "string", "function"],
42+
const VALID_TYPES = ["symbol", "undefined", "object", "boolean", "number", "string", "function", "bigint"],
4343
OPERATORS = ["==", "===", "!=", "!=="];
4444

4545
const requireStringLiterals = context.options[0] && context.options[0].requireStringLiterals;

tests/lib/rules/valid-typeof.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ ruleTester.run("valid-typeof", rule, {
2626
"typeof foo === 'undefined'",
2727
"typeof foo === 'boolean'",
2828
"typeof foo === 'number'",
29+
"typeof foo === 'bigint'",
2930
"'string' === typeof foo",
3031
"'object' === typeof foo",
3132
"'function' === typeof foo",

0 commit comments

Comments
 (0)