@typescript-eslint/eslint-plugin 8.50.1-alpha.1 → 8.50.1-alpha.3
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.
|
@@ -187,6 +187,30 @@ exports.default = (0, util_1.createRule)({
|
|
|
187
187
|
function isTypeLiteral(type) {
|
|
188
188
|
return type.isLiteral() || tsutils.isBooleanLiteralType(type);
|
|
189
189
|
}
|
|
190
|
+
function isIIFE(expression) {
|
|
191
|
+
return (expression.type === utils_1.AST_NODE_TYPES.CallExpression &&
|
|
192
|
+
(expression.callee.type === utils_1.AST_NODE_TYPES.ArrowFunctionExpression ||
|
|
193
|
+
expression.callee.type === utils_1.AST_NODE_TYPES.FunctionExpression));
|
|
194
|
+
}
|
|
195
|
+
function getUncastType(node) {
|
|
196
|
+
// Special handling for IIFE: extract the function's return type
|
|
197
|
+
if (isIIFE(node.expression)) {
|
|
198
|
+
const callee = node.expression.callee;
|
|
199
|
+
const functionType = services.getTypeAtLocation(callee);
|
|
200
|
+
const signatures = functionType.getCallSignatures();
|
|
201
|
+
if (signatures.length > 0) {
|
|
202
|
+
const returnType = checker.getReturnTypeOfSignature(signatures[0]);
|
|
203
|
+
// If the function has no explicit return type annotation and returns undefined,
|
|
204
|
+
// treat it as void (TypeScript infers () => {} as () => undefined, but it should be void)
|
|
205
|
+
if (callee.returnType == null &&
|
|
206
|
+
(0, util_1.isTypeFlagSet)(returnType, ts.TypeFlags.Undefined)) {
|
|
207
|
+
return checker.getVoidType();
|
|
208
|
+
}
|
|
209
|
+
return returnType;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
return services.getTypeAtLocation(node.expression);
|
|
213
|
+
}
|
|
190
214
|
return {
|
|
191
215
|
'TSAsExpression, TSTypeAssertion'(node) {
|
|
192
216
|
if (options.typesToIgnore?.includes(context.sourceCode.getText(node.typeAnnotation))) {
|
|
@@ -200,7 +224,7 @@ exports.default = (0, util_1.createRule)({
|
|
|
200
224
|
typeAnnotationIsConstAssertion) {
|
|
201
225
|
return;
|
|
202
226
|
}
|
|
203
|
-
const uncastType =
|
|
227
|
+
const uncastType = getUncastType(node);
|
|
204
228
|
const typeIsUnchanged = isTypeUnchanged(uncastType, castType);
|
|
205
229
|
const wouldSameTypeBeInferred = castTypeIsLiteral
|
|
206
230
|
? isImplicitlyNarrowedLiteralDeclaration(node)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@typescript-eslint/eslint-plugin",
|
|
3
|
-
"version": "8.50.1-alpha.
|
|
3
|
+
"version": "8.50.1-alpha.3",
|
|
4
4
|
"description": "TypeScript plugin for ESLint",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist",
|
|
@@ -59,10 +59,10 @@
|
|
|
59
59
|
},
|
|
60
60
|
"dependencies": {
|
|
61
61
|
"@eslint-community/regexpp": "^4.10.0",
|
|
62
|
-
"@typescript-eslint/scope-manager": "8.50.1-alpha.
|
|
63
|
-
"@typescript-eslint/type-utils": "8.50.1-alpha.
|
|
64
|
-
"@typescript-eslint/utils": "8.50.1-alpha.
|
|
65
|
-
"@typescript-eslint/visitor-keys": "8.50.1-alpha.
|
|
62
|
+
"@typescript-eslint/scope-manager": "8.50.1-alpha.3",
|
|
63
|
+
"@typescript-eslint/type-utils": "8.50.1-alpha.3",
|
|
64
|
+
"@typescript-eslint/utils": "8.50.1-alpha.3",
|
|
65
|
+
"@typescript-eslint/visitor-keys": "8.50.1-alpha.3",
|
|
66
66
|
"ignore": "^7.0.0",
|
|
67
67
|
"natural-compare": "^1.4.0",
|
|
68
68
|
"ts-api-utils": "^2.1.0"
|
|
@@ -70,8 +70,8 @@
|
|
|
70
70
|
"devDependencies": {
|
|
71
71
|
"@types/mdast": "^4.0.3",
|
|
72
72
|
"@types/natural-compare": "*",
|
|
73
|
-
"@typescript-eslint/rule-schema-to-typescript-types": "8.50.1-alpha.
|
|
74
|
-
"@typescript-eslint/rule-tester": "8.50.1-alpha.
|
|
73
|
+
"@typescript-eslint/rule-schema-to-typescript-types": "8.50.1-alpha.3",
|
|
74
|
+
"@typescript-eslint/rule-tester": "8.50.1-alpha.3",
|
|
75
75
|
"@vitest/coverage-v8": "^3.1.3",
|
|
76
76
|
"ajv": "^6.12.6",
|
|
77
77
|
"cross-fetch": "*",
|
|
@@ -91,7 +91,7 @@
|
|
|
91
91
|
"vitest": "^3.1.3"
|
|
92
92
|
},
|
|
93
93
|
"peerDependencies": {
|
|
94
|
-
"@typescript-eslint/parser": "^8.50.1-alpha.
|
|
94
|
+
"@typescript-eslint/parser": "^8.50.1-alpha.3",
|
|
95
95
|
"eslint": "^8.57.0 || ^9.0.0",
|
|
96
96
|
"typescript": ">=4.8.4 <6.0.0"
|
|
97
97
|
},
|