Typescript: Exported interface is transpiled to empty module

Created on 19 May 2017  路  4Comments  路  Source: microsoft/TypeScript



TypeScript Version: 2.3.2

Code

export interface A {
    a: boolean,
    b: number,
    c: string
}

Expected behavior:
It is not expected to be transpiled to JS code in any way if it is the only thing that is exported

Actual behavior:
It is transpiled to an empty module, like this for example:

define(["require", "exports"], function (require, exports) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    ;
});
Question

Most helpful comment

The compiler already elides imports that are only used in type position. So this file should never be imported at runtime.

We have discussed bundling in the past and the conclusion was that there are already abundance of bundlers, minifiers, optimizers and the like in the community and there is no reason to introduce yet another tool.

All 4 comments

A .ts file will always result in a .js file. Not emitting a file makes it hard to track issues like a stale .js file generated frim previous builds.
If you do not want any files generated change it to a .d.ts.

Ok, thanks for the explanation, I will definitely try the d.ts solution, but can this be implemented something like a tree shaking process on bundle creation?

The compiler already elides imports that are only used in type position. So this file should never be imported at runtime.

We have discussed bundling in the past and the conclusion was that there are already abundance of bundlers, minifiers, optimizers and the like in the community and there is no reason to introduce yet another tool.

Ok, thanks for the information.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

CyrusNajmabadi picture CyrusNajmabadi  路  3Comments

manekinekko picture manekinekko  路  3Comments

Antony-Jones picture Antony-Jones  路  3Comments

Roam-Cooper picture Roam-Cooper  路  3Comments

MartynasZilinskas picture MartynasZilinskas  路  3Comments