@typescript-eslint/eslint-plugin 8.0.0-alpha.3 → 8.0.0-alpha.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/configs/all.js +2 -5
- package/dist/configs/all.js.map +1 -1
- package/dist/configs/disable-type-checked.js +1 -2
- package/dist/configs/disable-type-checked.js.map +1 -1
- package/dist/configs/recommended-type-checked-only.js +6 -0
- package/dist/configs/recommended-type-checked-only.js.map +1 -1
- package/dist/configs/recommended-type-checked.js +11 -1
- package/dist/configs/recommended-type-checked.js.map +1 -1
- package/dist/configs/recommended.js +5 -1
- package/dist/configs/recommended.js.map +1 -1
- package/dist/configs/strict-type-checked-only.js +2 -2
- package/dist/configs/strict-type-checked-only.js.map +1 -1
- package/dist/configs/strict-type-checked.js +7 -4
- package/dist/configs/strict-type-checked.js.map +1 -1
- package/dist/configs/strict.js +5 -2
- package/dist/configs/strict.js.map +1 -1
- package/dist/configs/stylistic-type-checked-only.js +3 -0
- package/dist/configs/stylistic-type-checked-only.js.map +1 -1
- package/dist/configs/stylistic-type-checked.js +3 -2
- package/dist/configs/stylistic-type-checked.js.map +1 -1
- package/dist/configs/stylistic.js +0 -2
- package/dist/configs/stylistic.js.map +1 -1
- package/dist/rules/ban-types.js +4 -25
- package/dist/rules/ban-types.js.map +1 -1
- package/dist/rules/consistent-type-assertions.js +3 -5
- package/dist/rules/consistent-type-assertions.js.map +1 -1
- package/dist/rules/dot-notation.js +8 -1
- package/dist/rules/dot-notation.js.map +1 -1
- package/dist/rules/explicit-member-accessibility.js +98 -36
- package/dist/rules/explicit-member-accessibility.js.map +1 -1
- package/dist/rules/index.js +4 -4
- package/dist/rules/index.js.map +1 -1
- package/dist/rules/init-declarations.js +57 -1
- package/dist/rules/init-declarations.js.map +1 -1
- package/dist/rules/member-ordering.js +1 -2
- package/dist/rules/member-ordering.js.map +1 -1
- package/dist/rules/naming-convention-utils/parse-options.js +1 -3
- package/dist/rules/naming-convention-utils/parse-options.js.map +1 -1
- package/dist/rules/no-array-delete.js +1 -1
- package/dist/rules/no-array-delete.js.map +1 -1
- package/dist/rules/no-base-to-string.js +1 -1
- package/dist/rules/no-base-to-string.js.map +1 -1
- package/dist/rules/no-duplicate-type-constituents.js +1 -1
- package/dist/rules/no-duplicate-type-constituents.js.map +1 -1
- package/dist/rules/no-empty-interface.js +2 -1
- package/dist/rules/no-empty-interface.js.map +1 -1
- package/dist/rules/no-empty-object-type.js +141 -0
- package/dist/rules/no-empty-object-type.js.map +1 -0
- package/dist/rules/no-floating-promises.js +62 -39
- package/dist/rules/no-floating-promises.js.map +1 -1
- package/dist/rules/no-implied-eval.js.map +1 -1
- package/dist/rules/no-require-imports.js +13 -3
- package/dist/rules/no-require-imports.js.map +1 -1
- package/dist/rules/no-restricted-imports.js +3 -6
- package/dist/rules/no-restricted-imports.js.map +1 -1
- package/dist/rules/{no-useless-template-literals.js → no-unnecessary-template-expression.js} +6 -6
- package/dist/rules/no-unnecessary-template-expression.js.map +1 -0
- package/dist/rules/no-unnecessary-type-assertion.js +15 -13
- package/dist/rules/no-unnecessary-type-assertion.js.map +1 -1
- package/dist/rules/no-unsafe-argument.js +4 -2
- package/dist/rules/no-unsafe-argument.js.map +1 -1
- package/dist/rules/no-unsafe-assignment.js +24 -9
- package/dist/rules/no-unsafe-assignment.js.map +1 -1
- package/dist/rules/no-unsafe-return.js +1 -1
- package/dist/rules/no-unsafe-return.js.map +1 -1
- package/dist/rules/no-unsafe-unary-minus.js +1 -0
- package/dist/rules/no-unsafe-unary-minus.js.map +1 -1
- package/dist/rules/no-unused-expressions.js +1 -0
- package/dist/rules/no-unused-expressions.js.map +1 -1
- package/dist/rules/no-unused-vars.js +13 -3
- package/dist/rules/no-unused-vars.js.map +1 -1
- package/dist/rules/no-var-requires.js +2 -1
- package/dist/rules/no-var-requires.js.map +1 -1
- package/dist/rules/only-throw-error.js +1 -1
- package/dist/rules/only-throw-error.js.map +1 -1
- package/dist/rules/prefer-find.js +1 -0
- package/dist/rules/prefer-find.js.map +1 -1
- package/dist/rules/prefer-includes.js +1 -1
- package/dist/rules/prefer-includes.js.map +1 -1
- package/dist/rules/prefer-literal-enum-member.js +43 -2
- package/dist/rules/prefer-literal-enum-member.js.map +1 -1
- package/dist/rules/prefer-namespace-keyword.js +1 -1
- package/dist/rules/prefer-namespace-keyword.js.map +1 -1
- package/dist/rules/prefer-promise-reject-errors.js +1 -1
- package/dist/rules/prefer-promise-reject-errors.js.map +1 -1
- package/dist/rules/prefer-readonly.js +8 -5
- package/dist/rules/prefer-readonly.js.map +1 -1
- package/dist/rules/prefer-regexp-exec.js +15 -6
- package/dist/rules/prefer-regexp-exec.js.map +1 -1
- package/dist/rules/prefer-ts-expect-error.js +2 -1
- package/dist/rules/prefer-ts-expect-error.js.map +1 -1
- package/dist/rules/require-await.js +1 -1
- package/dist/rules/require-await.js.map +1 -1
- package/dist/rules/return-await.js +86 -55
- package/dist/rules/return-await.js.map +1 -1
- package/dist/rules/sort-type-constituents.js +23 -1
- package/dist/rules/sort-type-constituents.js.map +1 -1
- package/dist/rules/strict-boolean-expressions.js +1 -3
- package/dist/rules/strict-boolean-expressions.js.map +1 -1
- package/dist/rules/switch-exhaustiveness-check.js +7 -9
- package/dist/rules/switch-exhaustiveness-check.js.map +1 -1
- package/dist/rules/unified-signatures.js +3 -1
- package/dist/rules/unified-signatures.js.map +1 -1
- package/dist/util/collectUnusedVariables.js +22 -35
- package/dist/util/collectUnusedVariables.js.map +1 -1
- package/dist/util/createRule.js.map +1 -1
- package/dist/util/explicitReturnTypeUtils.js +5 -0
- package/dist/util/explicitReturnTypeUtils.js.map +1 -1
- package/dist/util/getFunctionHeadLoc.js.map +1 -1
- package/dist/util/getOperatorPrecedence.js +1 -1
- package/dist/util/getOperatorPrecedence.js.map +1 -1
- package/docs/rules/ban-types.mdx +5 -10
- package/docs/rules/consistent-type-imports.mdx +1 -1
- package/docs/rules/naming-convention.mdx +16 -0
- package/docs/rules/no-base-to-string.mdx +1 -1
- package/docs/rules/no-duplicate-imports.mdx +1 -1
- package/docs/rules/no-dynamic-delete.mdx +6 -2
- package/docs/rules/no-empty-interface.mdx +10 -0
- package/docs/rules/no-empty-object-type.mdx +145 -0
- package/docs/rules/no-floating-promises.mdx +103 -4
- package/docs/rules/no-import-type-side-effects.mdx +1 -1
- package/docs/rules/no-misused-promises.mdx +18 -20
- package/docs/rules/no-require-imports.mdx +28 -1
- package/docs/rules/no-unnecessary-boolean-literal-compare.mdx +12 -12
- package/docs/rules/no-unnecessary-template-expression.mdx +85 -0
- package/docs/rules/no-unused-expressions.mdx +41 -1
- package/docs/rules/no-unused-vars.mdx +5 -0
- package/docs/rules/no-useless-template-literals.mdx +3 -59
- package/docs/rules/no-var-requires.mdx +6 -0
- package/docs/rules/only-throw-error.mdx +7 -0
- package/docs/rules/prefer-readonly-parameter-types.mdx +10 -4
- package/docs/rules/prefer-ts-expect-error.mdx +10 -0
- package/docs/rules/require-await.mdx +2 -2
- package/docs/rules/restrict-template-expressions.mdx +1 -1
- package/docs/rules/return-await.mdx +39 -16
- package/docs/rules/sort-type-constituents.mdx +29 -9
- package/docs/rules/sort-type-union-intersection-members.mdx +12 -0
- package/docs/rules/unbound-method.mdx +3 -2
- package/package.json +14 -17
- package/rules.d.ts +6 -2
- package/dist/rules/no-throw-literal.js +0 -97
- package/dist/rules/no-throw-literal.js.map +0 -1
- package/dist/rules/no-useless-template-literals.js.map +0 -1
- package/docs/rules/no-throw-literal.mdx +0 -25
@@ -178,6 +178,7 @@ function getOperatorPrecedenceForNode(node) {
|
|
178
178
|
case utils_1.AST_NODE_TYPES.RestElement:
|
179
179
|
return OperatorPrecedence.Spread;
|
180
180
|
case utils_1.AST_NODE_TYPES.YieldExpression:
|
181
|
+
case utils_1.AST_NODE_TYPES.ArrowFunctionExpression:
|
181
182
|
return OperatorPrecedence.Yield;
|
182
183
|
case utils_1.AST_NODE_TYPES.ConditionalExpression:
|
183
184
|
return OperatorPrecedence.Conditional;
|
@@ -240,7 +241,6 @@ function getOperatorPrecedenceForNode(node) {
|
|
240
241
|
case utils_1.AST_NODE_TYPES.ArrayExpression:
|
241
242
|
case utils_1.AST_NODE_TYPES.ObjectExpression:
|
242
243
|
case utils_1.AST_NODE_TYPES.FunctionExpression:
|
243
|
-
case utils_1.AST_NODE_TYPES.ArrowFunctionExpression:
|
244
244
|
case utils_1.AST_NODE_TYPES.ClassExpression:
|
245
245
|
case utils_1.AST_NODE_TYPES.TemplateLiteral:
|
246
246
|
case utils_1.AST_NODE_TYPES.JSXElement:
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"getOperatorPrecedence.js","sourceRoot":"","sources":["../../src/util/getOperatorPrecedence.ts"],"names":[],"mappings":";;;AAEA,oDAA0D;AAC1D,2CAAwC;AAIxC,IAAY,kBA8LX;AA9LD,WAAY,kBAAkB;IAC5B,cAAc;IACd,2BAA2B;IAC3B,0CAA0C;IAC1C,6DAAK,CAAA;IAEL,iFAAiF;IACjF,iBAAiB;IACjB,iCAAiC;IACjC,+DAAM,CAAA;IAEN,wBAAwB;IACxB,4BAA4B;IAC5B,sBAAsB;IACtB,oBAAoB;IACpB,yBAAyB;IACzB,sDAAsD;IACtD,qEAAqE;IACrE,EAAE;IACF,6FAA6F;IAC7F,mCAAmC;IAEnC,wCAAwC;IACxC,mBAAmB;IACnB,cAAc;IACd,mCAAmC;IACnC,uCAAuC;IACvC,6DAAK,CAAA;IAEL,wEAAwE;IACxE,uFAAuF;IACvF,6BAA6B;IAC7B,uEAAuE;IACvE,uEAAU,CAAA;IAEV,4FAA4F;IAC5F,6BAA6B;IAC7B,8CAA8C;IAC9C,yBAAyB;IACzB,6BAA6B;IAC7B,+EAA+E;IAC/E,0BAA0B;IAC1B,0BAA0B;IAC1B,yBAAyB;IACzB,yEAAW,CAAA;IAEX,sBAAsB;IACtB,sDAAsD;IACtD,0BAA0B;IAC1B,yBAAyB;IACzB,0BAA0B;IAC1B,mEAAsB,CAAA;IAEtB,uBAAu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iB;IACjB,uBAAuB;IACvB,0BAA0B;IAC1B,4EAAY,CAAA;IAEZ,kBAAkB;IAClB,2CAA2C;IAC3C,gBAAgB;IAChB,iBAAiB;IACjB,+BAA+B;IAC/B,wCAAwC;IACxC,wCAAwC;IACxC,qCAAqC;IACrC,oBAAoB;IACpB,wBAAwB;IACxB,0CAA0C;IAC1C,0CAA0C;IAC1C,uCAAuC;IACvC,oBAAoB;IACpB,mBAAmB;IACnB,uCAAuC;IACvC,gEAAM,CAAA;IAEN,oBAAoB;IACpB,qBAAqB;IACrB,aAAa;IACb,0BAA0B;IAC1B,cAAc;IACd,mBAAmB;IACnB,oBAAoB;IACpB,yBAAyB;IACzB,sBAAsB;IACtB,0BAA0B;IAC1B,8BAA8B;IAC9B,+BAA+B;IAC/B,+BAA+B;IAC/B,sBAAsB;IACtB,wDAAwD;IACxD,kEAAO,CAAA;IAEP,kEAAiB,CAAA;IACjB,+DAAc,CAAA;IACd,oFAAoF;IACpF,mBAAmB;IACnB,kEAAY,CAAA;AACd,CAAC,EA9LW,kBAAkB,kCAAlB,kBAAkB,QA8L7B;AAED,SAAgB,4BAA4B,CAC1C,IAAmB;IAEnB,QAAQ,IAAI,CAAC,IAAI,EAAE,CAAC;QAClB,KAAK,sBAAc,CAAC,aAAa,CAAC;QAClC,KAAK,sBAAc,CAAC,WAAW;YAC7B,OAAO,kBAAkB,CAAC,MAAM,CAAC;QAEnC,KAAK,sBAAc,CAAC,eAAe;
|
1
|
+
{"version":3,"file":"getOperatorPrecedence.js","sourceRoot":"","sources":["../../src/util/getOperatorPrecedence.ts"],"names":[],"mappings":";;;AAEA,oDAA0D;AAC1D,2CAAwC;AAIxC,IAAY,kBA8LX;AA9LD,WAAY,kBAAkB;IAC5B,cAAc;IACd,2BAA2B;IAC3B,0CAA0C;IAC1C,6DAAK,CAAA;IAEL,iFAAiF;IACjF,iBAAiB;IACjB,iCAAiC;IACjC,+DAAM,CAAA;IAEN,wBAAwB;IACxB,4BAA4B;IAC5B,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;QACvD,KAAK,KAAK;YACR,OAAO,kBAAkB,CAAC,KAAK,CAAC;QAElC,KAAK,uBAAU,CAAC,SAAS,CAAC;QAC1B,KAAK,GAAG,CAAC;QACT,KAAK,uBAAU,CAAC,UAAU,CAAC;QAC3B,KAAK,GAAG;YACN,OAAO,kBAAkB,CAAC,QAAQ,CAAC;QAErC,KAAK,uBAAU,CAAC,aAAa,CAAC;QAC9B,KAAK,GAAG,CAAC;QACT,KAAK,uBAAU,CAAC,UAAU,CAAC;QAC3B,KAAK,GAAG,CAAC;QACT,KAAK,uBAAU,CAAC,YAAY,CAAC;QAC7B,KAAK,GAAG;YACN,OAAO,kBAAkB,CAAC,cAAc,CAAC;QAE3C,KAAK,uBAAU,CAAC,qBAAqB,CAAC;QACtC,KAAK,IAAI;YACP,OAAO,kBAAkB,CAAC,cAAc,CAAC;IAC7C,CAAC;IAED,qFAAqF;IACrF,mBAAmB;IACnB,OAAO,CAAC,CAAC,CAAC;AACZ,CAAC;AApFD,kEAoFC"}
|
package/docs/rules/ban-types.mdx
CHANGED
@@ -36,9 +36,6 @@ const func: Function = () => 1;
|
|
36
36
|
// use safer object types
|
37
37
|
const lowerObj: Object = {};
|
38
38
|
const capitalObj: Object = { a: 'string' };
|
39
|
-
|
40
|
-
const curly1: {} = 1;
|
41
|
-
const curly2: {} = { a: 'string' };
|
42
39
|
```
|
43
40
|
|
44
41
|
</TabItem>
|
@@ -58,9 +55,6 @@ const func: () => number = () => 1;
|
|
58
55
|
// use safer object types
|
59
56
|
const lowerObj: object = {};
|
60
57
|
const capitalObj: { a: string } = { a: 'string' };
|
61
|
-
|
62
|
-
const curly1: number = 1;
|
63
|
-
const curly2: Record<'a', string> = { a: 'string' };
|
64
58
|
```
|
65
59
|
|
66
60
|
</TabItem>
|
@@ -70,13 +64,10 @@ const curly2: Record<'a', string> = { a: 'string' };
|
|
70
64
|
|
71
65
|
The default options provide a set of "best practices", intended to provide safety and standardization in your codebase:
|
72
66
|
|
73
|
-
- Don't use the upper-case primitive types
|
67
|
+
- Don't use the upper-case primitive types or `Object`, you should use the lower-case types for consistency.
|
74
68
|
- Avoid the `Function` type, as it provides little safety for the following reasons:
|
75
69
|
- It provides no type safety when calling the value, which means it's easy to provide the wrong arguments.
|
76
70
|
- It accepts class declarations, which will fail when called, as they are called without the `new` keyword.
|
77
|
-
- Avoid the `Object` and `{}` types, as they mean "any non-nullish value".
|
78
|
-
- This is a point of confusion for many developers, who think it means "any object type".
|
79
|
-
- See [this comment for more information](https://github.com/typescript-eslint/typescript-eslint/issues/2063#issuecomment-675156492).
|
80
71
|
|
81
72
|
<details>
|
82
73
|
<summary>Default Options</summary>
|
@@ -136,3 +127,7 @@ Example configuration:
|
|
136
127
|
|
137
128
|
If your project is a rare one that intentionally deals with the class equivalents of primitives, it might not be worthwhile to enable the default `ban-types` options.
|
138
129
|
You might consider using [ESLint disable comments](https://eslint.org/docs/latest/use/configure/rules#using-configuration-comments-1) for those specific situations instead of completely disabling this rule.
|
130
|
+
|
131
|
+
## Related To
|
132
|
+
|
133
|
+
- [`no-empty-object-type`](./no-empty-object-type.mdx)
|
@@ -132,5 +132,5 @@ We recommend picking a single option for this rule that works best for your proj
|
|
132
132
|
## Related To
|
133
133
|
|
134
134
|
- [`no-import-type-side-effects`](./no-import-type-side-effects.mdx)
|
135
|
-
- [`import/consistent-type-specifier-style`](https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/consistent-type-specifier-style.
|
135
|
+
- [`import/consistent-type-specifier-style`](https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/consistent-type-specifier-style.md)
|
136
136
|
- [`import/no-duplicates` with `{"prefer-inline": true}`](https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-duplicates.md#inline-type-imports)
|
@@ -583,6 +583,22 @@ This allows you to emulate the old `interface-name-prefix` rule.
|
|
583
583
|
}
|
584
584
|
```
|
585
585
|
|
586
|
+
### Enforce that function names are either in camelCase or PascalCase
|
587
|
+
|
588
|
+
Function names are typically camelCase, but UI library components (especially JSX, such as React and Solid) use PascalCase to distinguish them from intrinsic elements. If you are writing function components, consider allowing both camelCase and PascalCase for functions.
|
589
|
+
|
590
|
+
```json
|
591
|
+
{
|
592
|
+
"@typescript-eslint/naming-convention": [
|
593
|
+
"error",
|
594
|
+
{
|
595
|
+
"selector": "function",
|
596
|
+
"format": ["camelCase", "PascalCase"]
|
597
|
+
}
|
598
|
+
]
|
599
|
+
}
|
600
|
+
```
|
601
|
+
|
586
602
|
### Enforce that variable and function names are in camelCase
|
587
603
|
|
588
604
|
This allows you to lint multiple type with same pattern.
|
@@ -10,7 +10,7 @@ import TabItem from '@theme/TabItem';
|
|
10
10
|
> See **https://typescript-eslint.io/rules/no-base-to-string** for documentation.
|
11
11
|
|
12
12
|
JavaScript will call `toString()` on an object when it is converted to a string, such as when `+` adding to a string or in `${}` template literals.
|
13
|
-
The default Object `.toString()`
|
13
|
+
The default Object `.toString()` uses the format `"[object Object]"`, which is often not what was intended.
|
14
14
|
This rule reports on stringified values that aren't primitives and don't define a more useful `.toString()` method.
|
15
15
|
|
16
16
|
> Note that `Function` provides its own `.toString()` that returns the function's code.
|
@@ -1,6 +1,6 @@
|
|
1
1
|
:::danger Deprecated
|
2
2
|
|
3
|
-
This rule has been deprecated in favour of the [`import/no-duplicates`](https://github.com/import-js/eslint-plugin-import/blob/HEAD/docs/rules/no-duplicates.
|
3
|
+
This rule has been deprecated in favour of the [`import/no-duplicates`](https://github.com/import-js/eslint-plugin-import/blob/HEAD/docs/rules/no-duplicates.md) rule.
|
4
4
|
|
5
5
|
:::
|
6
6
|
|
@@ -11,9 +11,13 @@ import TabItem from '@theme/TabItem';
|
|
11
11
|
|
12
12
|
Deleting dynamically computed keys can be dangerous and in some cases not well optimized.
|
13
13
|
Using the `delete` operator on keys that aren't runtime constants could be a sign that you're using the wrong data structures.
|
14
|
-
|
14
|
+
Consider using a `Map` or `Set` if you’re using an object as a key-value collection.
|
15
15
|
|
16
|
-
|
16
|
+
Dynamically adding and removing keys from objects can cause occasional edge case bugs. For example, some objects use "hidden properties" (such as `__data`) for private storage, and deleting them can break the object's internal state. Furthermore, [`delete`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/delete) cannot remove inherited properties or non-configurable properties. This makes it interact badly with anything more complicated than a plain object:
|
17
|
+
|
18
|
+
- The [`length`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/length) of an array is non-configurable, and deleting it is a runtime error.
|
19
|
+
- You can't remove properties on the prototype of an object, such as deleting methods from class instances.
|
20
|
+
- Sometimes, `delete` only removes the own property, leaving the inherited property intact. For example, deleting the [`name`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name) property of a function only removes the own property, but there's also a `Function.prototype.name` property that remains.
|
17
21
|
|
18
22
|
## Examples
|
19
23
|
|
@@ -9,6 +9,12 @@ import TabItem from '@theme/TabItem';
|
|
9
9
|
>
|
10
10
|
> See **https://typescript-eslint.io/rules/no-empty-interface** for documentation.
|
11
11
|
|
12
|
+
:::danger Deprecated
|
13
|
+
|
14
|
+
This rule has been deprecated in favour of the more comprehensive [`@typescript-eslint/no-empty-object-type`](./no-empty-object-type.mdx) rule.
|
15
|
+
|
16
|
+
:::
|
17
|
+
|
12
18
|
An empty interface in TypeScript does very little: any non-nullable value is assignable to `{}`.
|
13
19
|
Using an empty interface is often a sign of programmer error, such as misunderstanding the concept of `{}` or forgetting to fill in fields.
|
14
20
|
|
@@ -61,3 +67,7 @@ interface Baz extends Foo, Bar {}
|
|
61
67
|
## When Not To Use It
|
62
68
|
|
63
69
|
If you don't care about having empty/meaningless interfaces, then you will not need this rule.
|
70
|
+
|
71
|
+
## Related To
|
72
|
+
|
73
|
+
- [`no-empty-object-type`](./no-empty-object-type.mdx)
|
@@ -0,0 +1,145 @@
|
|
1
|
+
---
|
2
|
+
description: 'Disallow accidentally using the "empty object" type.'
|
3
|
+
---
|
4
|
+
|
5
|
+
import Tabs from '@theme/Tabs';
|
6
|
+
import TabItem from '@theme/TabItem';
|
7
|
+
|
8
|
+
> 🛑 This file is source code, not the primary documentation location! 🛑
|
9
|
+
>
|
10
|
+
> See **https://typescript-eslint.io/rules/no-empty-object-type** for documentation.
|
11
|
+
|
12
|
+
The `{}`, or "empty object" type in TypeScript is a common source of confusion for developers unfamiliar with TypeScript's structural typing.
|
13
|
+
`{}` represents any _non-nullish value_, including literals like `0` and `""`:
|
14
|
+
|
15
|
+
```ts
|
16
|
+
let anyNonNullishValue: {} = 'Intentionally allowed by TypeScript.';
|
17
|
+
```
|
18
|
+
|
19
|
+
Often, developers writing `{}` actually mean either:
|
20
|
+
|
21
|
+
- `object`: representing any _object_ value
|
22
|
+
- `unknown`: representing any value at all, including `null` and `undefined`
|
23
|
+
|
24
|
+
In other words, the "empty object" type `{}` really means _"any value that is defined"_.
|
25
|
+
That includes arrays, class instances, functions, and primitives such as `string` and `symbol`.
|
26
|
+
|
27
|
+
To avoid confusion around the `{}` type allowing any _non-nullish value_, this rule bans usage of the `{}` type.
|
28
|
+
That includes interfaces and object type aliases with no fields.
|
29
|
+
|
30
|
+
:::tip
|
31
|
+
If you do have a use case for an API allowing `{}`, you can always configure the [rule's options](#options), use an [ESLint disable comment](https://eslint.org/docs/latest/use/configure/rules#using-configuration-comments-1), or [disable the rule in your ESLint config](https://eslint.org/docs/latest/use/configure/rules#using-configuration-files-1).
|
32
|
+
:::
|
33
|
+
|
34
|
+
Note that this rule does not report on:
|
35
|
+
|
36
|
+
- `{}` as a type constituent in an intersection type (e.g. types like TypeScript's built-in `type NonNullable<T> = T & {}`), as this can be useful in type system operations.
|
37
|
+
- Interfaces that extend from multiple other interfaces.
|
38
|
+
|
39
|
+
## Examples
|
40
|
+
|
41
|
+
<Tabs>
|
42
|
+
<TabItem value="❌ Incorrect">
|
43
|
+
|
44
|
+
```ts
|
45
|
+
let anyObject: {};
|
46
|
+
let anyValue: {};
|
47
|
+
|
48
|
+
interface AnyObjectA {}
|
49
|
+
interface AnyValueA {}
|
50
|
+
|
51
|
+
type AnyObjectB = {};
|
52
|
+
type AnyValueB = {};
|
53
|
+
```
|
54
|
+
|
55
|
+
</TabItem>
|
56
|
+
<TabItem value="✅ Correct">
|
57
|
+
|
58
|
+
```ts
|
59
|
+
let anyObject: object;
|
60
|
+
let anyValue: unknown;
|
61
|
+
|
62
|
+
type AnyObjectA = object;
|
63
|
+
type AnyValueA = unknown;
|
64
|
+
|
65
|
+
type AnyObjectB = object;
|
66
|
+
type AnyValueB = unknown;
|
67
|
+
|
68
|
+
let objectWith: { property: boolean };
|
69
|
+
|
70
|
+
interface InterfaceWith {
|
71
|
+
property: boolean;
|
72
|
+
}
|
73
|
+
|
74
|
+
type TypeWith = { property: boolean };
|
75
|
+
```
|
76
|
+
|
77
|
+
</TabItem>
|
78
|
+
</Tabs>
|
79
|
+
|
80
|
+
## Options
|
81
|
+
|
82
|
+
By default, this rule flags both interfaces and object types.
|
83
|
+
|
84
|
+
### `allowInterfaces`
|
85
|
+
|
86
|
+
Whether to allow empty interfaces, as one of:
|
87
|
+
|
88
|
+
- `'always'`: to always allow interfaces with no fields
|
89
|
+
- `'never'` _(default)_: to never allow interfaces with no fields
|
90
|
+
- `'with-single-extends'`: to allow empty interfaces that `extend` from a single base interface
|
91
|
+
|
92
|
+
Examples of **correct** code for this rule with `{ allowInterfaces: 'with-single-extends' }`:
|
93
|
+
|
94
|
+
```ts option='{ "allowInterfaces": "with-single-extends" }' showPlaygroundButton
|
95
|
+
interface Base {
|
96
|
+
value: boolean;
|
97
|
+
}
|
98
|
+
|
99
|
+
interface Derived extends Base {}
|
100
|
+
```
|
101
|
+
|
102
|
+
### `allowObjectTypes`
|
103
|
+
|
104
|
+
Whether to allow empty object type literals, as one of:
|
105
|
+
|
106
|
+
- `'always'`: to always allow object type literals with no fields
|
107
|
+
- `'never'` _(default)_: to never allow object type literals with no fields
|
108
|
+
|
109
|
+
### `allowWithName`
|
110
|
+
|
111
|
+
A stringified regular expression to allow interfaces and object type aliases with the configured name.
|
112
|
+
This can be useful if your existing code style includes a pattern of declaring empty types with `{}` instead of `object`.
|
113
|
+
|
114
|
+
Examples of code for this rule with `{ allowWithName: 'Props$' }`:
|
115
|
+
|
116
|
+
<Tabs>
|
117
|
+
<TabItem value="❌ Incorrect">
|
118
|
+
|
119
|
+
```ts option='{ "allowWithName": "Props$" }' showPlaygroundButton
|
120
|
+
interface InterfaceValue {}
|
121
|
+
|
122
|
+
type TypeValue = {};
|
123
|
+
```
|
124
|
+
|
125
|
+
</TabItem>
|
126
|
+
<TabItem value="✅ Correct">
|
127
|
+
|
128
|
+
```ts option='{ "allowWithName": "Props$" }' showPlaygroundButton
|
129
|
+
interface InterfaceProps {}
|
130
|
+
|
131
|
+
type TypeProps = {};
|
132
|
+
```
|
133
|
+
|
134
|
+
</TabItem>
|
135
|
+
</Tabs>
|
136
|
+
|
137
|
+
## When Not To Use It
|
138
|
+
|
139
|
+
If your code commonly needs to represent the _"any non-nullish value"_ type, this rule may not be for you.
|
140
|
+
Projects that extensively use type operations such as conditional types and mapped types oftentimes benefit from disabling this rule.
|
141
|
+
|
142
|
+
## Further Reading
|
143
|
+
|
144
|
+
- [Enhancement: [ban-types] Split the {} ban into a separate, better-phrased rule](https://github.com/typescript-eslint/typescript-eslint/issues/8700)
|
145
|
+
- [The Empty Object Type in TypeScript](https://www.totaltypescript.com/the-empty-object-type-in-typescript)
|
@@ -17,13 +17,14 @@ Valid ways of handling a Promise-valued statement include:
|
|
17
17
|
|
18
18
|
- `await`ing it
|
19
19
|
- `return`ing it
|
20
|
+
- `void`ing it
|
20
21
|
- Calling its `.then()` with two arguments
|
21
22
|
- Calling its `.catch()` with one argument
|
22
23
|
|
23
24
|
This rule also reports when an Array containing Promises is created and not properly handled. The main way to resolve this is by using one of the Promise concurrency methods to create a single Promise, then handling that according to the procedure above. These methods include:
|
24
25
|
|
25
|
-
- `Promise.all()
|
26
|
-
- `Promise.allSettled()
|
26
|
+
- `Promise.all()`
|
27
|
+
- `Promise.allSettled()`
|
27
28
|
- `Promise.any()`
|
28
29
|
- `Promise.race()`
|
29
30
|
|
@@ -63,6 +64,9 @@ await promise;
|
|
63
64
|
async function returnsPromise() {
|
64
65
|
return 'value';
|
65
66
|
}
|
67
|
+
|
68
|
+
void returnsPromise();
|
69
|
+
|
66
70
|
returnsPromise().then(
|
67
71
|
() => {},
|
68
72
|
() => {},
|
@@ -82,7 +86,7 @@ await Promise.all([1, 2, 3].map(async x => x + 1));
|
|
82
86
|
|
83
87
|
### `ignoreVoid`
|
84
88
|
|
85
|
-
This allows you to stop the rule reporting promises consumed with void operator.
|
89
|
+
This option, which is `true` by default, allows you to stop the rule reporting promises consumed with void operator.
|
86
90
|
This can be a good way to explicitly mark a promise as intentionally not awaited.
|
87
91
|
|
88
92
|
Examples of **correct** code for this rule with `{ ignoreVoid: true }`:
|
@@ -100,7 +104,7 @@ With this option set to `true`, and if you are using `no-void`, you should turn
|
|
100
104
|
|
101
105
|
### `ignoreIIFE`
|
102
106
|
|
103
|
-
This allows you to skip checking of async IIFEs (Immediately Invoked
|
107
|
+
This allows you to skip checking of async IIFEs (Immediately Invoked Function Expressions).
|
104
108
|
|
105
109
|
Examples of **correct** code for this rule with `{ ignoreIIFE: true }`:
|
106
110
|
|
@@ -115,6 +119,101 @@ await (async function () {
|
|
115
119
|
})();
|
116
120
|
```
|
117
121
|
|
122
|
+
### `allowForKnownSafePromises`
|
123
|
+
|
124
|
+
This option allows marking specific types as "safe" to be floating. For example, you may need to do this in the case of libraries whose APIs return Promises whose rejections are safely handled by the library.
|
125
|
+
|
126
|
+
This option takes an array of type specifiers to consider safe.
|
127
|
+
Each item in the array must have one of the following forms:
|
128
|
+
|
129
|
+
- A type defined in a file (`{ from: "file", name: "Foo", path: "src/foo-file.ts" }` with `path` being an optional path relative to the project root directory)
|
130
|
+
- A type from the default library (`{ from: "lib", name: "PromiseLike" }`)
|
131
|
+
- A type from a package (`{ from: "package", name: "Foo", package: "foo-lib" }`, this also works for types defined in a typings package).
|
132
|
+
|
133
|
+
Examples of code for this rule with:
|
134
|
+
|
135
|
+
```json
|
136
|
+
{
|
137
|
+
"allowForKnownSafePromises": [
|
138
|
+
{ "from": "file", "name": "SafePromise" },
|
139
|
+
{ "from": "lib", "name": "PromiseLike" },
|
140
|
+
{ "from": "package", "name": "Bar", "package": "bar-lib" }
|
141
|
+
]
|
142
|
+
}
|
143
|
+
```
|
144
|
+
|
145
|
+
<Tabs>
|
146
|
+
<TabItem value="❌ Incorrect">
|
147
|
+
|
148
|
+
```ts option='{"allowForKnownSafePromises":[{"from":"file","name":"SafePromise"},{"from":"lib","name":"PromiseLike"},{"from":"package","name":"Bar","package":"bar-lib"}]}'
|
149
|
+
let promise: Promise<number> = Promise.resolve(2);
|
150
|
+
promise;
|
151
|
+
|
152
|
+
function returnsPromise(): Promise<number> {
|
153
|
+
return Promise.resolve(42);
|
154
|
+
}
|
155
|
+
|
156
|
+
returnsPromise();
|
157
|
+
```
|
158
|
+
|
159
|
+
</TabItem>
|
160
|
+
<TabItem value="✅ Correct">
|
161
|
+
|
162
|
+
```ts option='{"allowForKnownSafePromises":[{"from":"file","name":"SafePromise"},{"from":"lib","name":"PromiseLike"},{"from":"package","name":"Bar","package":"bar-lib"}]}'
|
163
|
+
// promises can be marked as safe by using branded types
|
164
|
+
type SafePromise = Promise<number> & { __linterBrands?: string };
|
165
|
+
|
166
|
+
let promise: SafePromise = Promise.resolve(2);
|
167
|
+
promise;
|
168
|
+
|
169
|
+
function returnsSafePromise(): SafePromise {
|
170
|
+
return Promise.resolve(42);
|
171
|
+
}
|
172
|
+
|
173
|
+
returnsSafePromise();
|
174
|
+
```
|
175
|
+
|
176
|
+
</TabItem>
|
177
|
+
</Tabs>
|
178
|
+
|
179
|
+
### `allowForKnownSafeCalls`
|
180
|
+
|
181
|
+
This option allows marking specific functions as "safe" to be called to create floating Promises.
|
182
|
+
For example, you may need to do this in the case of libraries whose APIs may be called without handling the resultant Promises.
|
183
|
+
|
184
|
+
This option takes the same array format as [`allowForKnownSafePromises`](#allowForKnownSafePromises).
|
185
|
+
|
186
|
+
Examples of code for this rule with:
|
187
|
+
|
188
|
+
```json
|
189
|
+
{
|
190
|
+
"allowForKnownSafeCalls": [
|
191
|
+
{ "from": "file", "name": "safe", "path": "input.ts" }
|
192
|
+
]
|
193
|
+
}
|
194
|
+
```
|
195
|
+
|
196
|
+
<Tabs>
|
197
|
+
<TabItem value="❌ Incorrect">
|
198
|
+
|
199
|
+
```ts option='{"allowForKnownSafeCalls":[{"from":"file","name":"safe","path":"input.ts"}]}'
|
200
|
+
declare function unsafe(...args: unknown[]): Promise<void>;
|
201
|
+
|
202
|
+
unsafe('...', () => {});
|
203
|
+
```
|
204
|
+
|
205
|
+
</TabItem>
|
206
|
+
<TabItem value="✅ Correct">
|
207
|
+
|
208
|
+
```ts option='{"allowForKnownSafeCalls":[{"from":"file","name":"safe","path":"input.ts"}]}' skipValidation
|
209
|
+
declare function safe(...args: unknown[]): Promise<void>;
|
210
|
+
|
211
|
+
safe('...', () => {});
|
212
|
+
```
|
213
|
+
|
214
|
+
</TabItem>
|
215
|
+
</Tabs>
|
216
|
+
|
118
217
|
## When Not To Use It
|
119
218
|
|
120
219
|
This rule can be difficult to enable on large existing projects that set up many floating Promises.
|
@@ -76,5 +76,5 @@ If you're not using TypeScript 5.0's `verbatimModuleSyntax` option and your proj
|
|
76
76
|
## Related To
|
77
77
|
|
78
78
|
- [`consistent-type-imports`](./consistent-type-imports.mdx)
|
79
|
-
- [`import/consistent-type-specifier-style`](https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/consistent-type-specifier-style.
|
79
|
+
- [`import/consistent-type-specifier-style`](https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/consistent-type-specifier-style.md)
|
80
80
|
- [`import/no-duplicates` with `{"prefer-inline": true}`](https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-duplicates.md#inline-type-imports)
|
@@ -127,19 +127,18 @@ Examples of code for this rule with `checksVoidReturn: true`:
|
|
127
127
|
|
128
128
|
```ts option='{ "checksVoidReturn": true }'
|
129
129
|
[1, 2, 3].forEach(async value => {
|
130
|
-
await
|
130
|
+
await fetch(`/${value}`);
|
131
131
|
});
|
132
132
|
|
133
|
-
new Promise(async (resolve, reject) => {
|
134
|
-
await
|
133
|
+
new Promise<void>(async (resolve, reject) => {
|
134
|
+
await fetch('/');
|
135
135
|
resolve();
|
136
136
|
});
|
137
137
|
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
otherSynchronousCall();
|
138
|
+
document.addEventListener('click', async () => {
|
139
|
+
console.log('synchronous call');
|
140
|
+
await fetch('/');
|
141
|
+
console.log('synchronous call');
|
143
142
|
});
|
144
143
|
```
|
145
144
|
|
@@ -169,8 +168,7 @@ new Promise((resolve, reject) => {
|
|
169
168
|
});
|
170
169
|
|
171
170
|
// Name the async wrapper to call it later
|
172
|
-
|
173
|
-
eventEmitter.on('some-event', () => {
|
171
|
+
document.addEventListener('click', () => {
|
174
172
|
const handler = async () => {
|
175
173
|
await doSomething();
|
176
174
|
otherSynchronousCall();
|
@@ -210,30 +208,30 @@ Examples of code for this rule with `checksSpreads: true`:
|
|
210
208
|
<TabItem value="❌ Incorrect">
|
211
209
|
|
212
210
|
```ts option='{ "checksSpreads": true }'
|
213
|
-
const getData = () =>
|
211
|
+
const getData = () => fetch('/');
|
214
212
|
|
215
|
-
|
213
|
+
console.log({ foo: 42, ...getData() });
|
216
214
|
|
217
|
-
const
|
218
|
-
await
|
215
|
+
const awaitData = async () => {
|
216
|
+
await fetch('/');
|
219
217
|
};
|
220
218
|
|
221
|
-
|
219
|
+
console.log({ foo: 42, ...awaitData() });
|
222
220
|
```
|
223
221
|
|
224
222
|
</TabItem>
|
225
223
|
<TabItem value="✅ Correct">
|
226
224
|
|
227
225
|
```ts option='{ "checksSpreads": true }'
|
228
|
-
const getData = () =>
|
226
|
+
const getData = () => fetch('/');
|
229
227
|
|
230
|
-
|
228
|
+
console.log({ foo: 42, ...(await getData()) });
|
231
229
|
|
232
|
-
const
|
233
|
-
await
|
230
|
+
const awaitData = async () => {
|
231
|
+
await fetch('/');
|
234
232
|
};
|
235
233
|
|
236
|
-
|
234
|
+
console.log({ foo: 42, ...(await awaitData()) });
|
237
235
|
```
|
238
236
|
|
239
237
|
</TabItem>
|
@@ -38,7 +38,7 @@ import * as lib3 from 'lib3';
|
|
38
38
|
|
39
39
|
### `allow`
|
40
40
|
|
41
|
-
|
41
|
+
An array of strings. These strings will be compiled into regular expressions with the `u` flag and be used to test against the imported path. A common use case is to allow importing `package.json`. This is because `package.json` commonly lives outside of the TS root directory, so statically importing it would lead to root directory conflicts, especially with `resolveJsonModule` enabled. You can also use it to allow importing any JSON if your environment doesn't support JSON modules, or use it for other cases where `import` statements cannot work.
|
42
42
|
|
43
43
|
With `{allow: ['/package\\.json$']}`:
|
44
44
|
|
@@ -59,6 +59,33 @@ console.log(require('../package.json').version);
|
|
59
59
|
</TabItem>
|
60
60
|
</Tabs>
|
61
61
|
|
62
|
+
### `allowAsImport`
|
63
|
+
|
64
|
+
When set to `true`, the `import x = require(...)` declaration won't be reported.
|
65
|
+
This is useful if you use certain module options that require strict CommonJS interop semantics.
|
66
|
+
|
67
|
+
With `{allowAsImport: true}`:
|
68
|
+
|
69
|
+
<Tabs>
|
70
|
+
<TabItem value="❌ Incorrect">
|
71
|
+
|
72
|
+
```ts option='{ "allowAsImport": true }'
|
73
|
+
var foo = require('foo');
|
74
|
+
const foo = require('foo');
|
75
|
+
let foo = require('foo');
|
76
|
+
```
|
77
|
+
|
78
|
+
</TabItem>
|
79
|
+
<TabItem value="✅ Correct">
|
80
|
+
|
81
|
+
```ts option='{ "allowAsImport": true }'
|
82
|
+
import foo = require('foo');
|
83
|
+
import foo from 'foo';
|
84
|
+
```
|
85
|
+
|
86
|
+
</TabItem>
|
87
|
+
</Tabs>
|
88
|
+
|
62
89
|
## When Not To Use It
|
63
90
|
|
64
91
|
If your project frequently uses older CommonJS `require`s, then this rule might not be applicable to you.
|