Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trailing comma in dynamic import should be allowed also when used in a typeof type #61489

Open
nicolo-ribaudo opened this issue Mar 26, 2025 · 1 comment Β· May be fixed by #61495
Open

Trailing comma in dynamic import should be allowed also when used in a typeof type #61489

nicolo-ribaudo opened this issue Mar 26, 2025 · 1 comment Β· May be fixed by #61495
Labels
Help Wanted You can do this Possible Improvement The current behavior isn't wrong, but it's possible to see that it might be better in some cases
Milestone

Comments

@nicolo-ribaudo
Copy link

nicolo-ribaudo commented Mar 26, 2025

πŸ”Ž Search Terms

trailing comma dynamic import

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried

⏯ Playground Link

https://www.typescriptlang.org/play/?#code/CYUwxgNghgTiAEBbA9sArhBAiAZs5W8A3gL4BQZYyAdgM4Au8AbvALzxQDuUAloz4gAOyGPQAUufFgA0ASgDcZegE9BCACpt4KtchzwBw0RLwE5iyjQbMATFq69+QkeMlnS5pao132OkHoGzsZuMh4KZEA

πŸ’» Code

declare module "foo" {}

const v = await import("foo",);
type T = typeof import("foo",);

const v2 = await import("foo",{},);
type T2 = typeof import("foo",{},);

πŸ™ Actual behavior

The trailing commas in the type-level import()s are reported as syntax error

πŸ™‚ Expected behavior

The syntax of import() at the type-level should match the one at the value level, thus allowing trailing commas.

Additional information about the issue

Note that the error was correct before import attributes, but import attributes changed the dynamic import syntax to allow trailing commas.

@nicolo-ribaudo
Copy link
Author

If this issues gets triaged as a real bug and anybody wants to open a PR, the fix will probably be by changing something in the parseImportType function in src/compiler/parser.ts

@nicolo-ribaudo nicolo-ribaudo linked a pull request Mar 27, 2025 that will close this issue
@RyanCavanaugh RyanCavanaugh added Help Wanted You can do this Possible Improvement The current behavior isn't wrong, but it's possible to see that it might be better in some cases labels Mar 27, 2025
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone Mar 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Help Wanted You can do this Possible Improvement The current behavior isn't wrong, but it's possible to see that it might be better in some cases
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants