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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Typescript mapped type with implicit any results in faulty TS #16393

Closed
1 task
aczekajski opened this issue Mar 29, 2024 · 1 comment 路 Fixed by #16394
Closed
1 task

[Bug]: Typescript mapped type with implicit any results in faulty TS #16393

aczekajski opened this issue Mar 29, 2024 · 1 comment 路 Fixed by #16394

Comments

@aczekajski
Copy link

馃捇

  • Would you like to work on a fix?

How are you using Babel?

Programmatic API (babel.transform, babel.parse)

Input code

type Bar = { [key in Foo] };

Configuration file name

No response

Configuration

options passed to @babel/parser:

{
    sourceType: 'module',
    plugins: ['typescript'],
}

Current and expected behavior

When just parsed using @babel/parser and generated back using @babel/generator, with nothing else being done to AST, the mentioned code becomes:

type Bar = { [key in Foo]: };

which is an ivalid typescript, raises "Type expected" error because indeed, there is no type after :.

Expected behavior:
It should be generated back into

type Bar = { [key in Foo] };

Environment

  • Babel: 7.24.3
  • @babel/plugin-syntax-typescript: 7.24.1
  • Node: 18.19.0
  • npm: 10.2.3

Possible solution

If the MappedType node has its type field set to undefined, there should be no : printed out after the [key in Foo].

Additional context

No response

@babel-bot
Copy link
Collaborator

Hey @aczekajski! We really appreciate you taking the time to report an issue. The collaborators on this project attempt to help as many people as possible, but we're a limited number of volunteers, so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack community that typically always has someone willing to help. You can sign-up here for an invite.

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

Successfully merging a pull request may close this issue.

3 participants