Skip to content

ASI not working after arguments-less new expression with type arguments #48654

@nicolo-ribaudo

Description

@nicolo-ribaudo

Bug Report

🔎 Search Terms

asi new expression type arguments

🕗 Version & Regression Information

TypeScript 4.7 Nightly (tested with the playground). This syntax has never been valid before TS 4.7.

new X<T>; is valid syntax since #47607 (cc @ahejlsberg)

⏯ Playground Link

Playground link with relevant code

💻 Code

class A<T> {}

new A<number>

if (0) {}

🙁 Actual behavior

It's parsed as if it was

class A<T> {}

new A<number> if (0) {}

thus it reports a few errors (number is used in a value position, and if is a reserved word).

🙂 Expected behavior

I would expect ASI to kick in, and to parse the code as if it was

class A<T> {}

new A<number>;

if (0) {}

Context

I'm implementing this in Babel. If it's expected that ASI does not work here, what are the rules to differentiate between a new expression with only type arguments, and a relational comparison?

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFix AvailableA PR has been opened for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions