@typescript-eslint/eslint-plugin 8.58.2-alpha.10 → 8.58.2-alpha.11
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.
|
@@ -424,7 +424,19 @@ exports.default = (0, util_1.createRule)({
|
|
|
424
424
|
const typeGuardAssertedArgument = (0, assertionFunctionUtils_1.findTypeGuardAssertedArgument)(services, node);
|
|
425
425
|
if (typeGuardAssertedArgument != null) {
|
|
426
426
|
const typeOfArgument = (0, util_1.getConstrainedTypeAtLocation)(services, typeGuardAssertedArgument.argument);
|
|
427
|
-
if (
|
|
427
|
+
if (
|
|
428
|
+
// Skip `any` — it is assignable to everything, producing
|
|
429
|
+
// false positives for meaningful runtime type guards.
|
|
430
|
+
!tsutils.isTypeFlagSet(typeOfArgument, ts.TypeFlags.Any | ts.TypeFlags.Unknown) &&
|
|
431
|
+
checker.isTypeAssignableTo(typeOfArgument, typeGuardAssertedArgument.type) &&
|
|
432
|
+
// Only flag if the types are mutually assignable (i.e. equivalent,
|
|
433
|
+
// like Narrower ↔ Wider with optional props) or the predicate type
|
|
434
|
+
// is a union that the argument is a strict subtype of. This avoids
|
|
435
|
+
// false positives with structural subtypes whose extra members are
|
|
436
|
+
// all optional in the *predicate* type (e.g. custom MappedType
|
|
437
|
+
// interfaces extending ts.Type).
|
|
438
|
+
(checker.isTypeAssignableTo(typeGuardAssertedArgument.type, typeOfArgument) ||
|
|
439
|
+
typeGuardAssertedArgument.type.isUnion())) {
|
|
428
440
|
context.report({
|
|
429
441
|
node: typeGuardAssertedArgument.argument,
|
|
430
442
|
messageId: 'typeGuardAlreadyIsType',
|
|
@@ -126,6 +126,8 @@ exports.default = (0, util_1.createRule)({
|
|
|
126
126
|
const paramIndex = parent.params.indexOf(node);
|
|
127
127
|
if (paramIndex !== -1) {
|
|
128
128
|
const tsFunc = services.esTreeNodeToTSNodeMap.get(parent);
|
|
129
|
+
// tsFunc is already a FunctionLike subtype; defensive runtime check
|
|
130
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
129
131
|
if (ts.isFunctionLike(tsFunc)) {
|
|
130
132
|
const contextualType = checker.getContextualType(tsFunc);
|
|
131
133
|
if (!contextualType) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@typescript-eslint/eslint-plugin",
|
|
3
|
-
"version": "8.58.2-alpha.
|
|
3
|
+
"version": "8.58.2-alpha.11",
|
|
4
4
|
"description": "TypeScript plugin for ESLint",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist",
|
|
@@ -52,10 +52,10 @@
|
|
|
52
52
|
"ignore": "^7.0.5",
|
|
53
53
|
"natural-compare": "^1.4.0",
|
|
54
54
|
"ts-api-utils": "^2.5.0",
|
|
55
|
-
"@typescript-eslint/scope-manager": "8.58.2-alpha.
|
|
56
|
-
"@typescript-eslint/type-utils": "8.58.2-alpha.
|
|
57
|
-
"@typescript-eslint/
|
|
58
|
-
"@typescript-eslint/
|
|
55
|
+
"@typescript-eslint/scope-manager": "8.58.2-alpha.11",
|
|
56
|
+
"@typescript-eslint/type-utils": "8.58.2-alpha.11",
|
|
57
|
+
"@typescript-eslint/visitor-keys": "8.58.2-alpha.11",
|
|
58
|
+
"@typescript-eslint/utils": "8.58.2-alpha.11"
|
|
59
59
|
},
|
|
60
60
|
"devDependencies": {
|
|
61
61
|
"@types/json-schema": "^7.0.15",
|
|
@@ -78,13 +78,13 @@
|
|
|
78
78
|
"typescript": ">=4.8.4 <6.1.0",
|
|
79
79
|
"unist-util-visit": "^5.0.0",
|
|
80
80
|
"vitest": "^4.0.18",
|
|
81
|
-
"@typescript-eslint/rule-
|
|
82
|
-
"@typescript-eslint/rule-
|
|
81
|
+
"@typescript-eslint/rule-schema-to-typescript-types": "8.58.2-alpha.11",
|
|
82
|
+
"@typescript-eslint/rule-tester": "8.58.2-alpha.11"
|
|
83
83
|
},
|
|
84
84
|
"peerDependencies": {
|
|
85
85
|
"eslint": "^8.57.0 || ^9.0.0 || ^10.0.0",
|
|
86
86
|
"typescript": ">=4.8.4 <6.1.0",
|
|
87
|
-
"@typescript-eslint/parser": "^8.58.2-alpha.
|
|
87
|
+
"@typescript-eslint/parser": "^8.58.2-alpha.11"
|
|
88
88
|
},
|
|
89
89
|
"funding": {
|
|
90
90
|
"type": "opencollective",
|