Skip to content

[@babel/preset-typescript] Namespace alias (native TS feature) is not supported #12345

@alker0

Description

@alker0

Bug Report

  • I would like to work on a fix!

import RenamedModule = OriginalModule is native Typescript's feature for creating module alias but @babel/preset-typescript does not allow this syntax.

Current behavior

@babel/preset-typescript gives an error.

Error: `import =` is not supported by @babel/plugin-transform-typescript
Please consider using `import <moduleName> from '<moduleName>';` alongside Typescript's --allowSyntheticDefaultImports option.

Input Code

declare module LongNameModule {
  export type SomeType = number;
}
import AliasModule = LongNameModule;

const some: AliasModule.SomeType = 3;
console.log(some);

Expected behavior

It outputs: 3.

Using tsc and ts-node, it is compiled as expected.

Babel Configuration (babel.config.js, .babelrc, package.json#babel, cli command, .eslintrc)

  • Filename: babel.config.js
{
  presets: [
    [
      '@babel/env',
      {
        modules: false,
        targets: {
          esmodules: true,
        },
      },
    ],
    [
      '@babel/typescript',
      {
        allowDeclareFields: true,
      },
    ],
  ],
};

Environment

  • Babel version: v7.12.3
  • Node/npm version: Node 14/yarn 1.22.10
  • OS: alpine linux (in docker)
  • Monorepo: no
  • How you are using Babel: cli

Possible Solution

I have no idea.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: typescripthelp wantedoutdatedA 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