@typescript-eslint/eslint-plugin 8.59.1-alpha.0 → 8.59.1-alpha.10

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.
@@ -51,7 +51,9 @@ function isAlwaysNullish(type) {
51
51
  * `any` or `unknown` to be nullable.
52
52
  */
53
53
  function isPossiblyNullish(type) {
54
- return tsutils.unionConstituents(type).some(isNullishType);
54
+ return tsutils
55
+ .unionConstituents(type)
56
+ .some(t => isNullishType(t) || (0, util_1.isTypeFlagSet)(t, ts.TypeFlags.Void));
55
57
  }
56
58
  function toStaticValue(type) {
57
59
  // type.isLiteral() only covers numbers/bigints and strings, hence the rest of the branches.
@@ -106,6 +106,11 @@ exports.default = (0, util_1.createRule)({
106
106
  }
107
107
  return {
108
108
  TSTypeParameterInstantiation(node) {
109
+ // TypeScript does not apply default type parameters in instantiation
110
+ // expressions, so explicit type args here are always meaningful.
111
+ if (node.parent.type === utils_1.AST_NODE_TYPES.TSInstantiationExpression) {
112
+ return;
113
+ }
109
114
  const expression = services.esTreeNodeToTSNodeMap.get(node);
110
115
  const typeParameters = getTypeParametersFromNode(node, expression, checker);
111
116
  if (typeParameters) {
@@ -218,7 +218,13 @@ exports.default = (0, util_1.createRule)({
218
218
  return type.isLiteral() || tsutils.isBooleanLiteralType(type);
219
219
  }
220
220
  function hasIndexSignature(type) {
221
- return checker.getIndexInfosOfType(type).length > 0;
221
+ return tsutils
222
+ .unionConstituents(type)
223
+ .some(part => checker.getIndexInfosOfType(part).length > 0);
224
+ }
225
+ function getTypeArguments(type) {
226
+ return (type.aliasTypeArguments ??
227
+ (tsutils.isTypeReference(type) ? checker.getTypeArguments(type) : []));
222
228
  }
223
229
  function typeContains(type, predicate, seen = new Set()) {
224
230
  if (seen.has(type)) {
@@ -232,7 +238,7 @@ exports.default = (0, util_1.createRule)({
232
238
  return type.types.some(t => typeContains(t, predicate, seen));
233
239
  }
234
240
  const nestedTypes = [
235
- ...checker.getTypeArguments(type),
241
+ ...getTypeArguments(type),
236
242
  ...type
237
243
  .getCallSignatures()
238
244
  .flatMap(sig => [
@@ -248,6 +254,9 @@ exports.default = (0, util_1.createRule)({
248
254
  function containsTypeVariable(type) {
249
255
  return typeContains(type, t => (0, util_1.isTypeFlagSet)(t, ts.TypeFlags.TypeVariable | ts.TypeFlags.Index));
250
256
  }
257
+ function hasPhantomTypeArguments(type) {
258
+ return isEmptyObjectType(type) && getTypeArguments(type).length > 0;
259
+ }
251
260
  function hasTypeParams(sig) {
252
261
  return (sig.getTypeParameters()?.length ?? 0) > 0;
253
262
  }
@@ -281,8 +290,8 @@ exports.default = (0, util_1.createRule)({
281
290
  });
282
291
  }
283
292
  function haveSameTypeArguments(uncast, cast) {
284
- const uncastArgs = checker.getTypeArguments(uncast);
285
- const castArgs = checker.getTypeArguments(cast);
293
+ const uncastArgs = getTypeArguments(uncast);
294
+ const castArgs = getTypeArguments(cast);
286
295
  return (uncastArgs.length === castArgs.length &&
287
296
  uncastArgs.every((arg, i) => arg === castArgs[i]));
288
297
  }
@@ -385,7 +394,7 @@ exports.default = (0, util_1.createRule)({
385
394
  if (param.valueDeclaration &&
386
395
  ts.isParameter(param.valueDeclaration) &&
387
396
  param.valueDeclaration.dotDotDotToken) {
388
- const typeArgs = checker.getTypeArguments(paramType);
397
+ const typeArgs = getTypeArguments(paramType);
389
398
  if (typeArgs.length > 0) {
390
399
  paramType = typeArgs[0];
391
400
  }
@@ -447,6 +456,14 @@ exports.default = (0, util_1.createRule)({
447
456
  const assignmentParent = parent.parent;
448
457
  return assignmentParent.type !== utils_1.AST_NODE_TYPES.ExpressionStatement;
449
458
  }
459
+ function isRightHandSideOfLogicalAssignment(node) {
460
+ const { parent } = node;
461
+ return (parent.type === utils_1.AST_NODE_TYPES.AssignmentExpression &&
462
+ parent.right === node &&
463
+ (parent.operator === '&&=' ||
464
+ parent.operator === '||=' ||
465
+ parent.operator === '??='));
466
+ }
450
467
  function isInGenericContext(node) {
451
468
  let seenFunction = false;
452
469
  for (let current = node.parent; current; current = current.parent) {
@@ -481,6 +498,12 @@ exports.default = (0, util_1.createRule)({
481
498
  }
482
499
  return false;
483
500
  }
501
+ function hasPhantomTypeArgumentMismatch(node, uncastType, contextualType) {
502
+ return (isInGenericContext(node) &&
503
+ (hasPhantomTypeArguments(uncastType) ||
504
+ hasPhantomTypeArguments(contextualType)) &&
505
+ !haveSameTypeArguments(uncastType, contextualType));
506
+ }
484
507
  const SKIP_PARENT_TYPES = new Set([
485
508
  utils_1.AST_NODE_TYPES.TSAsExpression,
486
509
  utils_1.AST_NODE_TYPES.TSTypeAssertion,
@@ -497,6 +520,7 @@ exports.default = (0, util_1.createRule)({
497
520
  isInDestructuringDeclaration(node) ||
498
521
  isPropertyInProblematicContext(node) ||
499
522
  isAssignmentInNonStatementContext(node) ||
523
+ isRightHandSideOfLogicalAssignment(node) ||
500
524
  isArgumentToOverloadedFunction(node)) {
501
525
  return true;
502
526
  }
@@ -612,6 +636,7 @@ exports.default = (0, util_1.createRule)({
612
636
  const isContextuallyUnnecessary = !typeAnnotationIsConstAssertion &&
613
637
  !containsAny(uncastType) &&
614
638
  anyInvolvedInContextualCheck &&
639
+ !hasPhantomTypeArgumentMismatch(node, uncastType, contextualType) &&
615
640
  (castIsAny || !genericsMismatch(uncastType, contextualType)) &&
616
641
  (contextualTypeIsAny ||
617
642
  checker.isTypeAssignableTo(uncastType, contextualType)) &&
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@typescript-eslint/eslint-plugin",
3
- "version": "8.59.1-alpha.0",
3
+ "version": "8.59.1-alpha.10",
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.59.1-alpha.0",
56
- "@typescript-eslint/utils": "8.59.1-alpha.0",
57
- "@typescript-eslint/type-utils": "8.59.1-alpha.0",
58
- "@typescript-eslint/visitor-keys": "8.59.1-alpha.0"
55
+ "@typescript-eslint/scope-manager": "8.59.1-alpha.10",
56
+ "@typescript-eslint/type-utils": "8.59.1-alpha.10",
57
+ "@typescript-eslint/visitor-keys": "8.59.1-alpha.10",
58
+ "@typescript-eslint/utils": "8.59.1-alpha.10"
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-tester": "8.59.1-alpha.0",
82
- "@typescript-eslint/rule-schema-to-typescript-types": "8.59.1-alpha.0"
81
+ "@typescript-eslint/rule-schema-to-typescript-types": "8.59.1-alpha.10",
82
+ "@typescript-eslint/rule-tester": "8.59.1-alpha.10"
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.59.1-alpha.0"
87
+ "@typescript-eslint/parser": "^8.59.1-alpha.10"
88
88
  },
89
89
  "funding": {
90
90
  "type": "opencollective",