Skip to content

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

@aczekajski

Description

@aczekajski

💻

  • 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: typescriptoutdatedA closed issue/PR that is archived due to age. Recommended to make a new issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions