Skip to content

ArrayExpression does not include SpreadElement as possible value of elements property #4963

@qnighy

Description

@qnighy

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

typescript-estree

Playground Link

https://www.typescriptlang.org/play?#code/JYWwDg9gTgLgBAbzgFQMoFFXKgUx3AXzgDMoIQ4ByAARgE8wcBnAYymDBgFpmAbYAHYwA9AFcYwXk0oBuALAAoRcVECWEiALi8IEMAHkAbjijpeOEDiFMAFAEMoUO3QBcKDFlw4AdAEFHzugAHmC4TEzAmgCUiIpwJNBwNiyaTPA45hQQxHAOTnTeGRZWMEwxCHHxcMLCcAASdgIAJuZwLHZMzNrAANb4KQJpuXAAvHAA2t5TAEYAuvIKVXDAOTZFIN70jKMjYwBEqKE4dk1mxUJ7MdO4dj0LSzVwTRBwTOQ4MAAWggDmCVBwL74HAhMIRTSVAiKKEKIA

Repro Code

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

function loopOverElements(array: TSESTree.ArrayExpression) {
  for (const elem of array.elements) {
    // Handle cases like const a = [...b];
    if (elem.type === "SpreadElement") break;
    // do something for the expression
  }
}

ESLint Config

No response

tsconfig

No response

Expected Result

The elem variable should have a type of TSESTree.Expression | TSESTree.SpreadElement and the code above should typecheck.

Actual Result

The elem variable has a type of TSESTree.Expression and the code above doesn't typecheck because the type of elem.type doesn't intersect with "SpreadElement".

Additional Info

No response

Versions

package version
@typescript-eslint/eslint-plugin 5.23.0
@typescript-eslint/parser 5.23.0
@typescript-eslint/scope-manager 5.23.0
@typescript-eslint/typescript-estree 5.23.0
@typescript-eslint/type-utils 5.23.0
@typescript-eslint/utils 5.23.0
TypeScript 4.6.4
ESLint 8.15.0
node 16.10.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    accepting prsGo ahead, send a pull request that resolves this issuebugSomething isn't workinggood first issueGood for newcomerspackage: ast-specIssues related to @typescript-eslint/ast-spec

    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