@typescript-eslint/eslint-plugin 8.25.1-alpha.15 → 8.25.1-alpha.17
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/rules/explicit-module-boundary-types.d.ts +1 -0
- package/dist/rules/explicit-module-boundary-types.d.ts.map +1 -1
- package/dist/rules/explicit-module-boundary-types.js +14 -0
- package/dist/rules/no-unnecessary-type-assertion.d.ts.map +1 -1
- package/dist/rules/no-unnecessary-type-assertion.js +4 -0
- package/docs/rules/explicit-module-boundary-types.mdx +14 -0
- package/package.json +7 -7
@@ -5,6 +5,7 @@ export type Options = [
|
|
5
5
|
allowedNames?: string[];
|
6
6
|
allowHigherOrderFunctions?: boolean;
|
7
7
|
allowTypedFunctionExpressions?: boolean;
|
8
|
+
allowOverloadFunctions?: boolean;
|
8
9
|
}
|
9
10
|
];
|
10
11
|
export type MessageIds = 'anyTypedArg' | 'anyTypedArgUnnamed' | 'missingArgType' | 'missingArgTypeUnnamed' | 'missingReturnType';
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"explicit-module-boundary-types.d.ts","sourceRoot":"","sources":["../../src/rules/explicit-module-boundary-types.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"explicit-module-boundary-types.d.ts","sourceRoot":"","sources":["../../src/rules/explicit-module-boundary-types.ts"],"names":[],"mappings":"AAyBA,MAAM,MAAM,OAAO,GAAG;IACpB;QACE,kCAAkC,CAAC,EAAE,OAAO,CAAC;QAC7C,yCAAyC,CAAC,EAAE,OAAO,CAAC;QACpD,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;QACxB,yBAAyB,CAAC,EAAE,OAAO,CAAC;QACpC,6BAA6B,CAAC,EAAE,OAAO,CAAC;QACxC,sBAAsB,CAAC,EAAE,OAAO,CAAC;KAClC;CACF,CAAC;AACF,MAAM,MAAM,UAAU,GAClB,aAAa,GACb,oBAAoB,GACpB,gBAAgB,GAChB,uBAAuB,GACvB,mBAAmB,CAAC;;AAExB,wBAweG"}
|
@@ -48,6 +48,10 @@ exports.default = (0, util_1.createRule)({
|
|
48
48
|
'You must still type the parameters of the function.',
|
49
49
|
].join('\n'),
|
50
50
|
},
|
51
|
+
allowOverloadFunctions: {
|
52
|
+
type: 'boolean',
|
53
|
+
description: 'Whether to ignore return type annotations on functions with overload signatures.',
|
54
|
+
},
|
51
55
|
allowTypedFunctionExpressions: {
|
52
56
|
type: 'boolean',
|
53
57
|
description: 'Whether to ignore type annotations on the variable of a function expression.',
|
@@ -62,6 +66,7 @@ exports.default = (0, util_1.createRule)({
|
|
62
66
|
allowDirectConstAssertionInArrowFunctions: true,
|
63
67
|
allowedNames: [],
|
64
68
|
allowHigherOrderFunctions: true,
|
69
|
+
allowOverloadFunctions: false,
|
65
70
|
allowTypedFunctionExpressions: true,
|
66
71
|
},
|
67
72
|
],
|
@@ -342,6 +347,11 @@ exports.default = (0, util_1.createRule)({
|
|
342
347
|
(0, explicitReturnTypeUtils_1.ancestorHasReturnType)(node)) {
|
343
348
|
return;
|
344
349
|
}
|
350
|
+
if (options.allowOverloadFunctions &&
|
351
|
+
node.parent.type === utils_1.AST_NODE_TYPES.MethodDefinition &&
|
352
|
+
(0, util_1.hasOverloadSignatures)(node.parent, context)) {
|
353
|
+
return;
|
354
|
+
}
|
345
355
|
(0, explicitReturnTypeUtils_1.checkFunctionExpressionReturnType)({ node, returns }, options, context.sourceCode, loc => {
|
346
356
|
context.report({
|
347
357
|
loc,
|
@@ -359,6 +369,10 @@ exports.default = (0, util_1.createRule)({
|
|
359
369
|
if (isAllowedName(node) || (0, explicitReturnTypeUtils_1.ancestorHasReturnType)(node)) {
|
360
370
|
return;
|
361
371
|
}
|
372
|
+
if (options.allowOverloadFunctions &&
|
373
|
+
(0, util_1.hasOverloadSignatures)(node, context)) {
|
374
|
+
return;
|
375
|
+
}
|
362
376
|
(0, explicitReturnTypeUtils_1.checkFunctionReturnType)({ node, returns }, options, context.sourceCode, loc => {
|
363
377
|
context.report({
|
364
378
|
loc,
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"no-unnecessary-type-assertion.d.ts","sourceRoot":"","sources":["../../src/rules/no-unnecessary-type-assertion.ts"],"names":[],"mappings":"AAqBA,MAAM,MAAM,OAAO,GAAG;IACpB;QACE,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;KAC1B;CACF,CAAC;AACF,MAAM,MAAM,UAAU,GAAG,yBAAyB,GAAG,sBAAsB,CAAC;;AAE5E,
|
1
|
+
{"version":3,"file":"no-unnecessary-type-assertion.d.ts","sourceRoot":"","sources":["../../src/rules/no-unnecessary-type-assertion.ts"],"names":[],"mappings":"AAqBA,MAAM,MAAM,OAAO,GAAG;IACpB;QACE,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;KAC1B;CACF,CAAC;AACF,MAAM,MAAM,UAAU,GAAG,yBAAyB,GAAG,sBAAsB,CAAC;;AAE5E,wBAwXG"}
|
@@ -260,6 +260,10 @@ exports.default = (0, util_1.createRule)({
|
|
260
260
|
// so figure out if the variable is used in a place that accepts nullable types
|
261
261
|
const contextualType = (0, util_1.getContextualType)(checker, originalNode);
|
262
262
|
if (contextualType) {
|
263
|
+
if ((0, util_1.isTypeFlagSet)(type, ts.TypeFlags.Unknown) &&
|
264
|
+
!(0, util_1.isTypeFlagSet)(contextualType, ts.TypeFlags.Unknown)) {
|
265
|
+
return;
|
266
|
+
}
|
263
267
|
// in strict mode you can't assign null to undefined, so we have to make sure that
|
264
268
|
// the two types share a nullable type
|
265
269
|
const typeIncludesUndefined = (0, util_1.isTypeFlagSet)(type, ts.TypeFlags.Undefined);
|
@@ -260,6 +260,20 @@ export const foo: FooType = bar => {};
|
|
260
260
|
</TabItem>
|
261
261
|
</Tabs>
|
262
262
|
|
263
|
+
### `allowOverloadFunctions`
|
264
|
+
|
265
|
+
{/* insert option description */}
|
266
|
+
|
267
|
+
Examples of correct code when `allowOverloadFunctions` is set to `true`:
|
268
|
+
|
269
|
+
```ts option='{ "allowOverloadFunctions": true }' showPlaygroundButton
|
270
|
+
export function test(a: string): string;
|
271
|
+
export function test(a: number): number;
|
272
|
+
export function test(a: unknown) {
|
273
|
+
return a;
|
274
|
+
}
|
275
|
+
```
|
276
|
+
|
263
277
|
## When Not To Use It
|
264
278
|
|
265
279
|
If your project is not used by downstream consumers that are sensitive to API types, you can disable this rule.
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@typescript-eslint/eslint-plugin",
|
3
|
-
"version": "8.25.1-alpha.
|
3
|
+
"version": "8.25.1-alpha.17",
|
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.25.1-alpha.
|
66
|
-
"@typescript-eslint/type-utils": "8.25.1-alpha.
|
67
|
-
"@typescript-eslint/utils": "8.25.1-alpha.
|
68
|
-
"@typescript-eslint/visitor-keys": "8.25.1-alpha.
|
65
|
+
"@typescript-eslint/scope-manager": "8.25.1-alpha.17",
|
66
|
+
"@typescript-eslint/type-utils": "8.25.1-alpha.17",
|
67
|
+
"@typescript-eslint/utils": "8.25.1-alpha.17",
|
68
|
+
"@typescript-eslint/visitor-keys": "8.25.1-alpha.17",
|
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.25.1-alpha.
|
80
|
-
"@typescript-eslint/rule-tester": "8.25.1-alpha.
|
79
|
+
"@typescript-eslint/rule-schema-to-typescript-types": "8.25.1-alpha.17",
|
80
|
+
"@typescript-eslint/rule-tester": "8.25.1-alpha.17",
|
81
81
|
"ajv": "^6.12.6",
|
82
82
|
"cross-env": "^7.0.3",
|
83
83
|
"cross-fetch": "*",
|