Skip to content

[Babel 7] [Typescript] Exported Interfaces from an import are kept in the generated JS code #8361

@manrueda

Description

@manrueda

Bug Report

Current Behavior
If the Typescript code exports an interfaces that was imported from other module, that interface reference is kept in the Javascript code after transpilation.

Input Code

File A:

export interface ExportedInterface {
  value: string
}

File B:

import { ExportedInterface } from './file-a';
export { ExportedInterface }

export function test(): ExportedInterface {
  return { value: '1' };
}

Expected behavior/code
The result code should not keep reference of that interface because is a type.

export function test() {
  return {
    value: '1'
  };
}

Babel Configuration (.babelrc, package.json, cli command)

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

Environment

  • Babel version(s): v7.0.0-beta.54
  • Node/npm version: Node 10.5.0/npm 6.2.0
  • OS: OSX 10.13.5
  • Monorepo no
  • How you are using Babel: cli (but is the same with loader)

Possible Solution
Looks like the here is a comment in the code that could be related to this issue: https://github.com/babel/babel/blob/master/packages/babel-plugin-transform-typescript/src/index.js#L52

Additional context/Screenshots
The generated code currently is the following one:

File A:

// No error, the file is generated empty

File B:

import { IInterface } from './test-sub';
export { IInterface };
export function test() {
  return {
    value: '1'
  };
}

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