Skip to content

Bug: SpreadElement does not allow NewExpression parent #10023

@eventualbuddha

Description

@eventualbuddha

Before You File a Bug Report Please Confirm You Have Done The Following...

  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.
  • I have searched for related issues and found none that matched my issue.
  • I have read the FAQ and my problem is not listed.

Relevant Package

types

Playground Link

https://typescript-eslint.io/play/#ts=5.5.2&showAST=es&fileType=.tsx&code=HYUw7gBAggTjCGBPAFAOnQbQLoEog&eslintrc=N4KABGBEBOCuA2BTAzpAXGYBfEWg&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylBm3TgwAXxCSgA&tokens=false

Repro Code

import {
  AST_NODE_TYPES,
  ESLintUtils,
  TSESTree,
} from '@typescript-eslint/utils';

export const listener: ESLintUtils.RuleListener = {
  SpreadElement(node: TSESTree.SpreadElement): void {
    switch (node.parent.type) {
      case AST_NODE_TYPES.NewExpression: {
        break;
      }
    }
  },
};

ESLint Config

No response

tsconfig

No response

Expected Result

I expect that comparing node.parent.type to AST_NODE_TYPES.NewExpression to be allowed when node is TSESTree.SpreadElement, but it isn't because TypeScript errors.

Actual Result

I get this error from TypeScript:

Type 'AST_NODE_TYPES.NewExpression' is not comparable to type 'AST_NODE_TYPES.ArrayExpression | AST_NODE_TYPES.CallExpression | AST_NODE_TYPES.ObjectExpression'. ts(2678)

Additional Info

A couple similar but not identical issues related to this:

Versions

package version
@typescript-eslint/eslint-plugin 8.6.0
@typescript-eslint/parser 8.6.0
@typescript-eslint/rule-tester 8.6.0
@typescript-eslint/scope-manager 8.6.0
@typescript-eslint/typescript-estree 8.6.0
@typescript-eslint/type-utils 8.6.0
@typescript-eslint/utils 8.6.0
TypeScript 5.5.3
ESLint 8.57.0
node 20.16.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinglocked due to agePlease open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing.triageWaiting for team members to take a look

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy