@typescript-eslint/eslint-plugin 8.70.2-alpha.3 → 8.70.2-alpha.4

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.
@@ -4,7 +4,7 @@ export type Options = [
4
4
  typesToIgnore?: string[];
5
5
  }
6
6
  ];
7
- export type MessageIds = 'contextuallyUnnecessary' | 'unnecessaryAssertion';
7
+ export type MessageIds = 'contextuallyInferredTypeArguments' | 'contextuallyUnnecessary' | 'unnecessaryAssertion';
8
8
  declare const _default: import("@typescript-eslint/utils/ts-eslint").RuleModule<MessageIds, Options, import("../../rules").ESLintPluginDocs, import("@typescript-eslint/utils/ts-eslint").RuleListener> & {
9
9
  name: string;
10
10
  };
@@ -48,6 +48,7 @@ exports.default = (0, util_1.createRule)({
48
48
  },
49
49
  fixable: 'code',
50
50
  messages: {
51
+ contextuallyInferredTypeArguments: 'The type arguments for this generic call may be inferred from the assertion. Specify them explicitly instead.',
51
52
  contextuallyUnnecessary: 'This assertion is unnecessary since the receiver accepts the original type of the expression.',
52
53
  unnecessaryAssertion: 'This assertion is unnecessary since it does not change the type of the expression.',
53
54
  },
@@ -381,6 +382,27 @@ exports.default = (0, util_1.createRule)({
381
382
  function hasGenericCallSignature(type) {
382
383
  return type.getCallSignatures().some(hasTypeParams);
383
384
  }
385
+ function getInnermostCall(expression) {
386
+ switch (expression.type) {
387
+ case utils_1.AST_NODE_TYPES.AwaitExpression:
388
+ return getInnermostCall(expression.argument);
389
+ case utils_1.AST_NODE_TYPES.CallExpression:
390
+ return expression;
391
+ case utils_1.AST_NODE_TYPES.ChainExpression:
392
+ case utils_1.AST_NODE_TYPES.TSNonNullExpression:
393
+ return getInnermostCall(expression.expression);
394
+ case utils_1.AST_NODE_TYPES.SequenceExpression:
395
+ return getInnermostCall((0, util_1.nullThrows)(expression.expressions.at(-1), 'Expected SequenceExpression to have at least one expression'));
396
+ default:
397
+ return undefined;
398
+ }
399
+ }
400
+ function isGenericCallWithInferredTypeArguments(expression) {
401
+ const call = getInnermostCall(expression);
402
+ return (call != null &&
403
+ call.typeArguments == null &&
404
+ hasGenericCallSignature(services.getTypeAtLocation(call.callee)));
405
+ }
384
406
  function isArgumentToOverloadedFunction(node) {
385
407
  const { parent } = node;
386
408
  if ((parent.type !== utils_1.AST_NODE_TYPES.CallExpression &&
@@ -647,11 +669,19 @@ exports.default = (0, util_1.createRule)({
647
669
  ? isImplicitlyNarrowedLiteralDeclaration(node)
648
670
  : !typeAnnotationIsConstAssertion;
649
671
  if (typeIsUnchanged && wouldSameTypeBeInferred) {
650
- context.report({
651
- node,
652
- messageId: 'unnecessaryAssertion',
653
- fix: createAssertionFixer(node),
654
- });
672
+ if (isGenericCallWithInferredTypeArguments(node.expression)) {
673
+ context.report({
674
+ node,
675
+ messageId: 'contextuallyInferredTypeArguments',
676
+ });
677
+ }
678
+ else {
679
+ context.report({
680
+ node,
681
+ messageId: 'unnecessaryAssertion',
682
+ fix: createAssertionFixer(node),
683
+ });
684
+ }
655
685
  return;
656
686
  }
657
687
  const originalNode = services.esTreeNodeToTSNodeMap.get(node);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@typescript-eslint/eslint-plugin",
3
- "version": "8.70.2-alpha.3",
3
+ "version": "8.70.2-alpha.4",
4
4
  "description": "TypeScript plugin for ESLint",
5
5
  "files": [
6
6
  "dist",
@@ -47,10 +47,10 @@
47
47
  ],
48
48
  "dependencies": {
49
49
  "@eslint-community/regexpp": "^4.12.2",
50
- "@typescript-eslint/scope-manager": "8.70.2-alpha.3",
51
- "@typescript-eslint/type-utils": "8.70.2-alpha.3",
52
- "@typescript-eslint/utils": "8.70.2-alpha.3",
53
- "@typescript-eslint/visitor-keys": "8.70.2-alpha.3",
50
+ "@typescript-eslint/scope-manager": "8.70.2-alpha.4",
51
+ "@typescript-eslint/type-utils": "8.70.2-alpha.4",
52
+ "@typescript-eslint/utils": "8.70.2-alpha.4",
53
+ "@typescript-eslint/visitor-keys": "8.70.2-alpha.4",
54
54
  "ignore": "^7.0.5",
55
55
  "natural-compare": "^1.4.0",
56
56
  "ts-api-utils": "^2.5.0"
@@ -60,8 +60,8 @@
60
60
  "@types/mdast": "^4.0.4",
61
61
  "@types/natural-compare": "^1.4.3",
62
62
  "@types/react": "^18.3.21",
63
- "@typescript-eslint/rule-schema-to-typescript-types": "8.70.2-alpha.3",
64
- "@typescript-eslint/rule-tester": "8.70.2-alpha.3",
63
+ "@typescript-eslint/rule-schema-to-typescript-types": "8.70.2-alpha.4",
64
+ "@typescript-eslint/rule-tester": "8.70.2-alpha.4",
65
65
  "@typescript/native": "npm:typescript@^7.0.2",
66
66
  "@vitest/coverage-v8": "^4.0.18",
67
67
  "ajv": "^6.12.6",
@@ -81,7 +81,7 @@
81
81
  "vitest": "^4.0.18"
82
82
  },
83
83
  "peerDependencies": {
84
- "@typescript-eslint/parser": "^8.70.2-alpha.3",
84
+ "@typescript-eslint/parser": "^8.70.2-alpha.4",
85
85
  "eslint": "^8.57.0 || ^9.0.0 || ^10.0.0",
86
86
  "typescript": ">=4.8.4 <6.1.0"
87
87
  },