@typescript-eslint/eslint-plugin 8.24.2-alpha.3 → 8.25.0
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/index.d.ts +1 -1
- package/dist/rules/index.d.ts +1 -1
- package/dist/rules/no-deprecated.d.ts.map +1 -1
- package/dist/rules/no-deprecated.js +11 -1
- package/dist/rules/no-floating-promises.d.ts.map +1 -1
- package/dist/rules/no-floating-promises.js +1 -4
- package/dist/rules/no-inferrable-types.d.ts.map +1 -1
- package/dist/rules/no-inferrable-types.js +4 -6
- package/dist/rules/no-invalid-void-type.d.ts.map +1 -1
- package/dist/rules/no-invalid-void-type.js +22 -0
- package/dist/rules/no-misused-spread.d.ts +3 -2
- package/dist/rules/no-misused-spread.d.ts.map +1 -1
- package/dist/rules/no-misused-spread.js +50 -0
- package/dist/rules/prefer-find.d.ts.map +1 -1
- package/dist/rules/prefer-find.js +8 -11
- package/dist/rules/prefer-nullish-coalescing.d.ts.map +1 -1
- package/dist/rules/prefer-nullish-coalescing.js +61 -26
- package/dist/rules/prefer-promise-reject-errors.d.ts.map +1 -1
- package/dist/rules/prefer-promise-reject-errors.js +2 -7
- package/dist/rules/prefer-string-starts-ends-with.d.ts.map +1 -1
- package/dist/rules/prefer-string-starts-ends-with.js +3 -11
- package/dist/rules/return-await.d.ts.map +1 -1
- package/dist/rules/return-await.js +1 -10
- package/dist/rules/strict-boolean-expressions.d.ts +2 -1
- package/dist/rules/strict-boolean-expressions.d.ts.map +1 -1
- package/dist/rules/strict-boolean-expressions.js +457 -512
- package/dist/rules/unified-signatures.d.ts.map +1 -1
- package/dist/rules/unified-signatures.js +10 -3
- package/dist/util/hasOverloadSignatures.d.ts +7 -0
- package/dist/util/hasOverloadSignatures.d.ts.map +1 -0
- package/dist/util/hasOverloadSignatures.js +47 -0
- package/dist/util/index.d.ts +3 -0
- package/dist/util/index.d.ts.map +1 -1
- package/dist/util/index.js +3 -0
- package/dist/util/isHigherPrecedenceThanAwait.d.ts +3 -0
- package/dist/util/isHigherPrecedenceThanAwait.d.ts.map +1 -0
- package/dist/util/isHigherPrecedenceThanAwait.js +46 -0
- package/dist/util/skipChainExpression.d.ts +3 -0
- package/dist/util/skipChainExpression.d.ts.map +1 -0
- package/dist/util/skipChainExpression.js +7 -0
- package/docs/rules/consistent-type-definitions.mdx +43 -4
- package/package.json +7 -7
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"unified-signatures.d.ts","sourceRoot":"","sources":["../../src/rules/unified-signatures.ts"],"names":[],"mappings":"AAuDA,MAAM,MAAM,UAAU,GAClB,uBAAuB,GACvB,yBAAyB,GACzB,2BAA2B,CAAC;AAEhC,MAAM,MAAM,OAAO,GAAG;IACpB;QACE,gCAAgC,CAAC,EAAE,OAAO,CAAC;KAC5C;CACF,CAAC;;AAEF,
|
1
|
+
{"version":3,"file":"unified-signatures.d.ts","sourceRoot":"","sources":["../../src/rules/unified-signatures.ts"],"names":[],"mappings":"AAuDA,MAAM,MAAM,UAAU,GAClB,uBAAuB,GACvB,yBAAyB,GACzB,2BAA2B,CAAC;AAEhC,MAAM,MAAM,OAAO,GAAG;IACpB;QACE,gCAAgC,CAAC,EAAE,OAAO,CAAC;KAC5C;CACF,CAAC;;AAEF,wBA2gBG"}
|
@@ -334,12 +334,12 @@ exports.default = (0, util_1.createRule)({
|
|
334
334
|
TSTypeLiteral: createScope,
|
335
335
|
// collect overloads
|
336
336
|
MethodDefinition(node) {
|
337
|
-
if (!node.value.body) {
|
337
|
+
if (!node.value.body && !isGetterOrSetter(node)) {
|
338
338
|
addOverload(node);
|
339
339
|
}
|
340
340
|
},
|
341
341
|
TSAbstractMethodDefinition(node) {
|
342
|
-
if (!node.value.body) {
|
342
|
+
if (!node.value.body && !isGetterOrSetter(node)) {
|
343
343
|
addOverload(node);
|
344
344
|
}
|
345
345
|
},
|
@@ -349,7 +349,11 @@ exports.default = (0, util_1.createRule)({
|
|
349
349
|
const exportingNode = getExportingNode(node);
|
350
350
|
addOverload(node, node.id?.name ?? exportingNode?.type, exportingNode);
|
351
351
|
},
|
352
|
-
TSMethodSignature
|
352
|
+
TSMethodSignature(node) {
|
353
|
+
if (!isGetterOrSetter(node)) {
|
354
|
+
addOverload(node);
|
355
|
+
}
|
356
|
+
},
|
353
357
|
// validate scopes
|
354
358
|
'ClassDeclaration:exit': checkScope,
|
355
359
|
'Program:exit': checkScope,
|
@@ -396,3 +400,6 @@ function getStaticParameterName(param) {
|
|
396
400
|
function isIdentifier(node) {
|
397
401
|
return node.type === utils_1.AST_NODE_TYPES.Identifier;
|
398
402
|
}
|
403
|
+
function isGetterOrSetter(node) {
|
404
|
+
return node.kind === 'get' || node.kind === 'set';
|
405
|
+
}
|
@@ -0,0 +1,7 @@
|
|
1
|
+
import type { TSESTree } from '@typescript-eslint/utils';
|
2
|
+
import type { RuleContext } from '@typescript-eslint/utils/ts-eslint';
|
3
|
+
/**
|
4
|
+
* @return `true` if the function or method node has overload signatures.
|
5
|
+
*/
|
6
|
+
export declare function hasOverloadSignatures(node: TSESTree.FunctionDeclaration | TSESTree.MethodDefinition, context: RuleContext<string, unknown[]>): boolean;
|
7
|
+
//# sourceMappingURL=hasOverloadSignatures.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"hasOverloadSignatures.d.ts","sourceRoot":"","sources":["../../src/util/hasOverloadSignatures.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oCAAoC,CAAC;AAMtE;;GAEG;AACH,wBAAgB,qBAAqB,CACnC,IAAI,EAAE,QAAQ,CAAC,mBAAmB,GAAG,QAAQ,CAAC,gBAAgB,EAC9D,OAAO,EAAE,WAAW,CAAC,MAAM,EAAE,OAAO,EAAE,CAAC,GACtC,OAAO,CAqCT"}
|
@@ -0,0 +1,47 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.hasOverloadSignatures = hasOverloadSignatures;
|
4
|
+
const utils_1 = require("@typescript-eslint/utils");
|
5
|
+
const misc_1 = require("./misc");
|
6
|
+
/**
|
7
|
+
* @return `true` if the function or method node has overload signatures.
|
8
|
+
*/
|
9
|
+
function hasOverloadSignatures(node, context) {
|
10
|
+
// `export default function () {}`
|
11
|
+
if (node.parent.type === utils_1.AST_NODE_TYPES.ExportDefaultDeclaration) {
|
12
|
+
return node.parent.parent.body.some(member => {
|
13
|
+
return (member.type === utils_1.AST_NODE_TYPES.ExportDefaultDeclaration &&
|
14
|
+
member.declaration.type === utils_1.AST_NODE_TYPES.TSDeclareFunction);
|
15
|
+
});
|
16
|
+
}
|
17
|
+
// `export function f() {}`
|
18
|
+
if (node.parent.type === utils_1.AST_NODE_TYPES.ExportNamedDeclaration) {
|
19
|
+
return node.parent.parent.body.some(member => {
|
20
|
+
return (member.type === utils_1.AST_NODE_TYPES.ExportNamedDeclaration &&
|
21
|
+
member.declaration?.type === utils_1.AST_NODE_TYPES.TSDeclareFunction &&
|
22
|
+
getFunctionDeclarationName(member.declaration, context) ===
|
23
|
+
getFunctionDeclarationName(node, context));
|
24
|
+
});
|
25
|
+
}
|
26
|
+
// either:
|
27
|
+
// - `function f() {}`
|
28
|
+
// - `class T { foo() {} }`
|
29
|
+
const nodeKey = getFunctionDeclarationName(node, context);
|
30
|
+
return node.parent.body.some(member => {
|
31
|
+
return ((member.type === utils_1.AST_NODE_TYPES.TSDeclareFunction ||
|
32
|
+
(member.type === utils_1.AST_NODE_TYPES.MethodDefinition &&
|
33
|
+
member.value.body == null)) &&
|
34
|
+
nodeKey === getFunctionDeclarationName(member, context));
|
35
|
+
});
|
36
|
+
}
|
37
|
+
function getFunctionDeclarationName(node, context) {
|
38
|
+
if (node.type === utils_1.AST_NODE_TYPES.FunctionDeclaration ||
|
39
|
+
node.type === utils_1.AST_NODE_TYPES.TSDeclareFunction) {
|
40
|
+
// For a `FunctionDeclaration` or `TSDeclareFunction` this may be `null` if
|
41
|
+
// and only if the parent is an `ExportDefaultDeclaration`.
|
42
|
+
//
|
43
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
44
|
+
return node.id.name;
|
45
|
+
}
|
46
|
+
return (0, misc_1.getStaticMemberAccessValue)(node, context);
|
47
|
+
}
|
package/dist/util/index.d.ts
CHANGED
@@ -10,6 +10,7 @@ export * from './getStringLength';
|
|
10
10
|
export * from './getTextWithParentheses';
|
11
11
|
export * from './getThisExpression';
|
12
12
|
export * from './getWrappingFixer';
|
13
|
+
export * from './hasOverloadSignatures';
|
13
14
|
export * from './isArrayMethodCallWithPredicate';
|
14
15
|
export * from './isAssignee';
|
15
16
|
export * from './isNodeEqual';
|
@@ -24,6 +25,8 @@ export * from './scopeUtils';
|
|
24
25
|
export * from './types';
|
25
26
|
export * from './getConstraintInfo';
|
26
27
|
export * from './getValueOfLiteralType';
|
28
|
+
export * from './isHigherPrecedenceThanAwait';
|
29
|
+
export * from './skipChainExpression';
|
27
30
|
export * from './truthinessAndNullishUtils';
|
28
31
|
export * from '@typescript-eslint/type-utils';
|
29
32
|
export declare const applyDefault: typeof ESLintUtils.applyDefault, deepMerge: typeof ESLintUtils.deepMerge, getParserServices: typeof ESLintUtils.getParserServices, isObjectNotArray: typeof ESLintUtils.isObjectNotArray, nullThrows: typeof ESLintUtils.nullThrows, NullThrowsReasons: {
|
package/dist/util/index.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/util/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAEvD,cAAc,YAAY,CAAC;AAC3B,cAAc,0BAA0B,CAAC;AACzC,cAAc,cAAc,CAAC;AAC7B,cAAc,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,CAAC;AACrC,cAAc,yBAAyB,CAAC;AACxC,cAAc,wBAAwB,CAAC;AACvC,cAAc,mBAAmB,CAAC;AAClC,cAAc,0BAA0B,CAAC;AACzC,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC;AACnC,cAAc,kCAAkC,CAAC;AACjD,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,yBAAyB,CAAC;AACxC,cAAc,QAAQ,CAAC;AACvB,cAAc,2BAA2B,CAAC;AAC1C,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC;AACxB,cAAc,qBAAqB,CAAC;AACpC,cAAc,yBAAyB,CAAC;AACxC,cAAc,6BAA6B,CAAC;AAG5C,cAAc,+BAA+B,CAAC;AAE9C,eAAO,MACL,YAAY,mCACZ,SAAS,gCACT,iBAAiB,wCACjB,gBAAgB,uCAChB,UAAU,iCACV,iBAAiB;;;CACJ,CAAC;AAChB,MAAM,MAAM,2BAA2B,CAAC,CAAC,IACvC,WAAW,CAAC,2BAA2B,CAAC,CAAC,CAAC,CAAC;AAC7C,MAAM,MAAM,wBAAwB,CAAC,CAAC,IACpC,WAAW,CAAC,wBAAwB,CAAC,CAAC,CAAC,CAAC"}
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/util/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAEvD,cAAc,YAAY,CAAC;AAC3B,cAAc,0BAA0B,CAAC;AACzC,cAAc,cAAc,CAAC;AAC7B,cAAc,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,CAAC;AACrC,cAAc,yBAAyB,CAAC;AACxC,cAAc,wBAAwB,CAAC;AACvC,cAAc,mBAAmB,CAAC;AAClC,cAAc,0BAA0B,CAAC;AACzC,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC;AACnC,cAAc,yBAAyB,CAAC;AACxC,cAAc,kCAAkC,CAAC;AACjD,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,yBAAyB,CAAC;AACxC,cAAc,QAAQ,CAAC;AACvB,cAAc,2BAA2B,CAAC;AAC1C,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC;AACxB,cAAc,qBAAqB,CAAC;AACpC,cAAc,yBAAyB,CAAC;AACxC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,uBAAuB,CAAC;AACtC,cAAc,6BAA6B,CAAC;AAG5C,cAAc,+BAA+B,CAAC;AAE9C,eAAO,MACL,YAAY,mCACZ,SAAS,gCACT,iBAAiB,wCACjB,gBAAgB,uCAChB,UAAU,iCACV,iBAAiB;;;CACJ,CAAC;AAChB,MAAM,MAAM,2BAA2B,CAAC,CAAC,IACvC,WAAW,CAAC,2BAA2B,CAAC,CAAC,CAAC,CAAC;AAC7C,MAAM,MAAM,wBAAwB,CAAC,CAAC,IACpC,WAAW,CAAC,wBAAwB,CAAC,CAAC,CAAC,CAAC"}
|
package/dist/util/index.js
CHANGED
@@ -27,6 +27,7 @@ __exportStar(require("./getStringLength"), exports);
|
|
27
27
|
__exportStar(require("./getTextWithParentheses"), exports);
|
28
28
|
__exportStar(require("./getThisExpression"), exports);
|
29
29
|
__exportStar(require("./getWrappingFixer"), exports);
|
30
|
+
__exportStar(require("./hasOverloadSignatures"), exports);
|
30
31
|
__exportStar(require("./isArrayMethodCallWithPredicate"), exports);
|
31
32
|
__exportStar(require("./isAssignee"), exports);
|
32
33
|
__exportStar(require("./isNodeEqual"), exports);
|
@@ -41,6 +42,8 @@ __exportStar(require("./scopeUtils"), exports);
|
|
41
42
|
__exportStar(require("./types"), exports);
|
42
43
|
__exportStar(require("./getConstraintInfo"), exports);
|
43
44
|
__exportStar(require("./getValueOfLiteralType"), exports);
|
45
|
+
__exportStar(require("./isHigherPrecedenceThanAwait"), exports);
|
46
|
+
__exportStar(require("./skipChainExpression"), exports);
|
44
47
|
__exportStar(require("./truthinessAndNullishUtils"), exports);
|
45
48
|
// this is done for convenience - saves migrating all of the old rules
|
46
49
|
__exportStar(require("@typescript-eslint/type-utils"), exports);
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"isHigherPrecedenceThanAwait.d.ts","sourceRoot":"","sources":["../../src/util/isHigherPrecedenceThanAwait.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,YAAY,CAAC;AAIjC,wBAAgB,2BAA2B,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,GAAG,OAAO,CAUpE"}
|
@@ -0,0 +1,46 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
|
+
if (k2 === undefined) k2 = k;
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
7
|
+
}
|
8
|
+
Object.defineProperty(o, k2, desc);
|
9
|
+
}) : (function(o, m, k, k2) {
|
10
|
+
if (k2 === undefined) k2 = k;
|
11
|
+
o[k2] = m[k];
|
12
|
+
}));
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
15
|
+
}) : function(o, v) {
|
16
|
+
o["default"] = v;
|
17
|
+
});
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
19
|
+
var ownKeys = function(o) {
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
21
|
+
var ar = [];
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
23
|
+
return ar;
|
24
|
+
};
|
25
|
+
return ownKeys(o);
|
26
|
+
};
|
27
|
+
return function (mod) {
|
28
|
+
if (mod && mod.__esModule) return mod;
|
29
|
+
var result = {};
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
31
|
+
__setModuleDefault(result, mod);
|
32
|
+
return result;
|
33
|
+
};
|
34
|
+
})();
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
36
|
+
exports.isHigherPrecedenceThanAwait = isHigherPrecedenceThanAwait;
|
37
|
+
const ts = __importStar(require("typescript"));
|
38
|
+
const getOperatorPrecedence_1 = require("./getOperatorPrecedence");
|
39
|
+
function isHigherPrecedenceThanAwait(tsNode) {
|
40
|
+
const operator = ts.isBinaryExpression(tsNode)
|
41
|
+
? tsNode.operatorToken.kind
|
42
|
+
: ts.SyntaxKind.Unknown;
|
43
|
+
const nodePrecedence = (0, getOperatorPrecedence_1.getOperatorPrecedence)(tsNode.kind, operator);
|
44
|
+
const awaitPrecedence = (0, getOperatorPrecedence_1.getOperatorPrecedence)(ts.SyntaxKind.AwaitExpression, ts.SyntaxKind.Unknown);
|
45
|
+
return nodePrecedence > awaitPrecedence;
|
46
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"skipChainExpression.d.ts","sourceRoot":"","sources":["../../src/util/skipChainExpression.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAIzD,wBAAgB,mBAAmB,CAAC,CAAC,SAAS,QAAQ,CAAC,IAAI,EACzD,IAAI,EAAE,CAAC,GACN,CAAC,GAAG,QAAQ,CAAC,YAAY,CAE3B"}
|
@@ -0,0 +1,7 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.skipChainExpression = skipChainExpression;
|
4
|
+
const utils_1 = require("@typescript-eslint/utils");
|
5
|
+
function skipChainExpression(node) {
|
6
|
+
return node.type === utils_1.AST_NODE_TYPES.ChainExpression ? node.expression : node;
|
7
|
+
}
|
@@ -82,13 +82,52 @@ type T = { x: number };
|
|
82
82
|
</TabItem>
|
83
83
|
</Tabs>
|
84
84
|
|
85
|
+
## FAQs
|
86
|
+
|
87
|
+
### What are the differences between `interface` and `type`?
|
88
|
+
|
89
|
+
There are very few differences between interfaces and object types in TypeScript.
|
90
|
+
Other than type aliases being used to represent union types, it is rare that you will need to choose one over the other.
|
91
|
+
|
92
|
+
| Feature | Interfaces | Object Types | Explanation |
|
93
|
+
| --------------------- | ---------- | ------------ | ------------------------------------------------------------------------------------------------------ |
|
94
|
+
| Object shapes | ✅ | ✅ | Both can be used to represent general object shapes. |
|
95
|
+
| General performance | ✅ | ✅ | Both are optimized for performance in TypeScript's type checker. |
|
96
|
+
| Edge case performance | ✅ | | Large, complex logical types can be optimized better with interfaces by TypeScript's type checker. |
|
97
|
+
| Traditional semantics | ✅ | | Interfaces are typically the default in much -though not all- of the TypeScript community. |
|
98
|
+
| Non-object shapes | | ✅ | Object types may describe literals, primitives, unions, and intersections. |
|
99
|
+
| Logical types | | ✅ | Object types may include conditional and mapped types. |
|
100
|
+
| Merging | Allowed | Not allowed | Interfaces of the same name are treated as one interface ("merged"); type aliases may not share names. |
|
101
|
+
|
102
|
+
We recommend choosing one definition style, using it when possible, and falling back to the other style when needed.
|
103
|
+
The benefits of remaining consistent within a codebase almost always outweigh the benefits of either definition style.
|
104
|
+
|
105
|
+
### When do the performance differences between `interface` and `type` matter?
|
106
|
+
|
107
|
+
Almost never.
|
108
|
+
Most TypeScript projects do not -and should not- utilize types that exercise the performance differences between the two kinds of definitions.
|
109
|
+
|
110
|
+
If you are having problems with type checking performance, see the [TypeScript Wiki's Performance page](https://github.com/microsoft/TypeScript/wiki/Performance).
|
111
|
+
|
112
|
+
### Why is the default `interface`?
|
113
|
+
|
114
|
+
Interfaces are the prevailing, most common style in the TypeScript.
|
115
|
+
`interface` has traditionally been TypeScript's intended ("semantic") way to convey _"an object with these fields"_.
|
116
|
+
|
117
|
+
We generally recommend staying with the default, `'interface'`, to be stylistically consistent with the majority of TypeScript projects.
|
118
|
+
If you strongly prefer `'type'`, that's fine too.
|
119
|
+
|
85
120
|
## When Not To Use It
|
86
121
|
|
87
|
-
If you specifically want to use an interface or type literal for stylistic reasons, you can avoid this rule.
|
122
|
+
If you specifically want to manually choose whether to use an interface or type literal for stylistic reasons each time you define a type, you can avoid this rule.
|
88
123
|
|
89
124
|
However, keep in mind that inconsistent style can harm readability in a project.
|
90
125
|
We recommend picking a single option for this rule that works best for your project.
|
91
126
|
|
92
|
-
|
93
|
-
|
94
|
-
|
127
|
+
You might occasionally need to a different definition type in specific cases, such as if your project is a dependency or dependent of another project that relies on a specific type definition style.
|
128
|
+
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.
|
129
|
+
|
130
|
+
## Further Reading
|
131
|
+
|
132
|
+
- [TypeScript Handbook > Everyday Types > Differences Between Type Aliases and Interfaces](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#differences-between-type-aliases-and-interfaces)
|
133
|
+
- [StackOverflow: Interfaces vs Types in TypeScript](https://stackoverflow.com/questions/37233735/interfaces-vs-types-in-typescript)
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@typescript-eslint/eslint-plugin",
|
3
|
-
"version": "8.
|
3
|
+
"version": "8.25.0",
|
4
4
|
"description": "TypeScript plugin for ESLint",
|
5
5
|
"files": [
|
6
6
|
"dist",
|
@@ -62,10 +62,10 @@
|
|
62
62
|
},
|
63
63
|
"dependencies": {
|
64
64
|
"@eslint-community/regexpp": "^4.10.0",
|
65
|
-
"@typescript-eslint/scope-manager": "8.
|
66
|
-
"@typescript-eslint/type-utils": "8.
|
67
|
-
"@typescript-eslint/utils": "8.
|
68
|
-
"@typescript-eslint/visitor-keys": "8.
|
65
|
+
"@typescript-eslint/scope-manager": "8.25.0",
|
66
|
+
"@typescript-eslint/type-utils": "8.25.0",
|
67
|
+
"@typescript-eslint/utils": "8.25.0",
|
68
|
+
"@typescript-eslint/visitor-keys": "8.25.0",
|
69
69
|
"graphemer": "^1.4.0",
|
70
70
|
"ignore": "^5.3.1",
|
71
71
|
"natural-compare": "^1.4.0",
|
@@ -76,8 +76,8 @@
|
|
76
76
|
"@types/marked": "^5.0.2",
|
77
77
|
"@types/mdast": "^4.0.3",
|
78
78
|
"@types/natural-compare": "*",
|
79
|
-
"@typescript-eslint/rule-schema-to-typescript-types": "8.
|
80
|
-
"@typescript-eslint/rule-tester": "8.
|
79
|
+
"@typescript-eslint/rule-schema-to-typescript-types": "8.25.0",
|
80
|
+
"@typescript-eslint/rule-tester": "8.25.0",
|
81
81
|
"ajv": "^6.12.6",
|
82
82
|
"cross-env": "^7.0.3",
|
83
83
|
"cross-fetch": "*",
|