Skip to content

Bug: NewExpression doesn't allow SpreadElement as argument #5421

@burtek

Description

@burtek

Before You File a Proposal Please Confirm You Have Done The Following...

Relevant Package

ast-spec

My proposal is suitable for this project

  • I believe my proposal would be useful to the broader TypeScript community (meaning it is not a niche proposal).

Description

NewExpression and CallExpression are basically identical in terms of arguments list. Among others, you're perfectly fine with spreading arguments in both of them:

class A { constructor(...args: unknown[]) {} }
const a = new A(...someArray);

const F = (...args: unknown[]) => {}
const f = F(...someArray);

That is reflected in CallExpression type:

export interface CallExpression extends BaseNode {
type: AST_NODE_TYPES.CallExpression;
callee: LeftHandSideExpression;
arguments: CallExpressionArgument[];

With CallExpressionArgument being:
export type CallExpressionArgument = Expression | SpreadElement;

At the same time, NewExpression typing allows only Expression arguments:

export interface NewExpression extends BaseNode {
type: AST_NODE_TYPES.NewExpression;
callee: LeftHandSideExpression;
arguments: Expression[];

SpreadElement is not there, even though it is legal to spread arguments in constructor call (playground)

Fail

n/a

Pass

n/a

Additional Info

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    accepting prsGo ahead, send a pull request that resolves this issuebugSomething isn't working

    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