@typescript-eslint/eslint-plugin 8.59.1-alpha.1 → 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,12 +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);
222
224
  }
223
225
  function getTypeArguments(type) {
224
- return tsutils.isTypeReference(type)
225
- ? checker.getTypeArguments(type)
226
- : [];
226
+ return (type.aliasTypeArguments ??
227
+ (tsutils.isTypeReference(type) ? checker.getTypeArguments(type) : []));
227
228
  }
228
229
  function typeContains(type, predicate, seen = new Set()) {
229
230
  if (seen.has(type)) {
@@ -253,6 +254,9 @@ exports.default = (0, util_1.createRule)({
253
254
  function containsTypeVariable(type) {
254
255
  return typeContains(type, t => (0, util_1.isTypeFlagSet)(t, ts.TypeFlags.TypeVariable | ts.TypeFlags.Index));
255
256
  }
257
+ function hasPhantomTypeArguments(type) {
258
+ return isEmptyObjectType(type) && getTypeArguments(type).length > 0;
259
+ }
256
260
  function hasTypeParams(sig) {
257
261
  return (sig.getTypeParameters()?.length ?? 0) > 0;
258
262
  }
@@ -452,6 +456,14 @@ exports.default = (0, util_1.createRule)({
452
456
  const assignmentParent = parent.parent;
453
457
  return assignmentParent.type !== utils_1.AST_NODE_TYPES.ExpressionStatement;
454
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
+ }
455
467
  function isInGenericContext(node) {
456
468
  let seenFunction = false;
457
469
  for (let current = node.parent; current; current = current.parent) {
@@ -486,6 +498,12 @@ exports.default = (0, util_1.createRule)({
486
498
  }
487
499
  return false;
488
500
  }
501
+ function hasPhantomTypeArgumentMismatch(node, uncastType, contextualType) {
502
+ return (isInGenericContext(node) &&
503
+ (hasPhantomTypeArguments(uncastType) ||
504
+ hasPhantomTypeArguments(contextualType)) &&
505
+ !haveSameTypeArguments(uncastType, contextualType));
506
+ }
489
507
  const SKIP_PARENT_TYPES = new Set([
490
508
  utils_1.AST_NODE_TYPES.TSAsExpression,
491
509
  utils_1.AST_NODE_TYPES.TSTypeAssertion,
@@ -502,6 +520,7 @@ exports.default = (0, util_1.createRule)({
502
520
  isInDestructuringDeclaration(node) ||
503
521
  isPropertyInProblematicContext(node) ||
504
522
  isAssignmentInNonStatementContext(node) ||
523
+ isRightHandSideOfLogicalAssignment(node) ||
505
524
  isArgumentToOverloadedFunction(node)) {
506
525
  return true;
507
526
  }
@@ -617,6 +636,7 @@ exports.default = (0, util_1.createRule)({
617
636
  const isContextuallyUnnecessary = !typeAnnotationIsConstAssertion &&
618
637
  !containsAny(uncastType) &&
619
638
  anyInvolvedInContextualCheck &&
639
+ !hasPhantomTypeArgumentMismatch(node, uncastType, contextualType) &&
620
640
  (castIsAny || !genericsMismatch(uncastType, contextualType)) &&
621
641
  (contextualTypeIsAny ||
622
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.1",
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.1",
56
- "@typescript-eslint/type-utils": "8.59.1-alpha.1",
57
- "@typescript-eslint/visitor-keys": "8.59.1-alpha.1",
58
- "@typescript-eslint/utils": "8.59.1-alpha.1"
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-schema-to-typescript-types": "8.59.1-alpha.1",
82
- "@typescript-eslint/rule-tester": "8.59.1-alpha.1"
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.1"
87
+ "@typescript-eslint/parser": "^8.59.1-alpha.10"
88
88
  },
89
89
  "funding": {
90
90
  "type": "opencollective",