Skip to content

import<T> is valid syntax in nightly #48759

Closed
@evanw

Description

@evanw
Contributor

Bug Report

Context: I'm trying to figure out how to update esbuild to handle the latest ASI-related behavior changes that just landed (#48755 and #48659). In the process, I discovered this weird TypeScript behavior that I believe was an oversight. I assume #47607 introduced the regression since it landed around the same time.

I tried to dig through code history to understand this better. It looks like isStartOfLeftHandSideExpression allows < after import due to #16544, although no tests were added for import followed by < in that PR. So I'm assuming TypeScript only allows < after import for parser recovery, which I don't need to support in esbuild.

🔎 Search Terms

regression import expression type parameters missing arguments

🕗 Version & Regression Information

  • This changed between versions 4.7.0-dev.20220216 and 4.7.0-dev.20220217

⏯ Playground Link

Playground link with relevant code

💻 Code

import<T>;
let foo = import<foo, bar>;

🙁 Actual behavior

The nightly TypeScript compiler converts the above TypeScript code into the following JavaScript without any errors:

"use strict";
import;
let foo = (import);

🙂 Expected behavior

I either expected the TypeScript compiler to consider this invalid syntax, or if it's valid syntax I expected it to give type errors for the missing type names.

Activity

fatcerberus

fatcerberus commented on Apr 19, 2022

@fatcerberus

4.6.2 produces this error for a dynamic import with type arguments:

Dynamic import cannot have type arguments.

let foo = import; is also not valid JS, so this definitely looks like an oversight.

added this to the Backlog milestone on Apr 19, 2022
DanielRosenwasser

DanielRosenwasser commented on Apr 29, 2022

@DanielRosenwasser
Member

Thanks @a-tarasyuk!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFix AvailableA PR has been opened for this issueHelp WantedYou can do this

Type

No type

Projects

No projects

Relationships

None yet

    Development

    Participants

    @evanw@DanielRosenwasser@fatcerberus@ahejlsberg@RyanCavanaugh

    Issue actions

      `import<T>` is valid syntax in nightly · Issue #48759 · microsoft/TypeScript