Skip to content

[Bug]: Babel with Typescript produces functions for an empty namespaces. #14947

@qisoft

Description

@qisoft

💻

  • Would you like to work on a fix?

How are you using Babel?

babel-loader (webpack)

Input code

export namespace A {}
export namespace B {
    interface C {} 
}

Configuration file name

.babelrc

Configuration

{
    "presets": [
        [
            "@babel/preset-env",
            {
                "modules": false
            }
        ],
        [
            "@babel/preset-typescript",
            {
                "allowNamespaces": true
            }
        ]
    ]
}

Current and expected behavior

Current behavior:
Babel produces consts and empty functions for these namespaces.

Expected behavior:
Babel should ignore them the same way as TypeScript compiler does.

This is useful when you have a React component and a namespace with the same name containing the Props interface inside. This allows you to import { ComponentName } from './ComponentName' without additional import for Props type by accessing it with ComponentName.Props. Such namespace exists in types scope only and should not affect the resulting code. There is no sense and use of such function produced from these empty namespaces, it's just garbage.

Environment

  • Babel version: 7.19.1
  • Node version: 16

Possible solution

No response

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