TypeScript icon indicating copy to clipboard operation
TypeScript copied to clipboard

Export * for interfaces generates redundant JS

Open Koloto opened this issue 11 years ago • 2 comments

I have a fileinterfaces.d.ts which defines some interfaces, e.g:

export interface IFoo {}
export interface IBar {}

I want to reexport all interfaces in another module:

export * from "interfaces";

When targeting AMD, compiled code looks like this:

define(["require", "exports", "interfaces"], function (require, exports, interfaces_1) {
    function __export(m) {
        for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
    }
    __export(interfaces_1);
});

Module "interfaces" should not be imported at all, because it doesn't contain any JS code. To fix this I have to list all exported interfaces manually:

export { IFoo, IBar } from "interfaces";

It's a problem if the number of interfaces is large.

I use version 1.5.3.

Koloto avatar Aug 27 '15 13:08 Koloto

Just curious as to why it's a problem if the number of interfaces are large, given that interfaces have no runtime representation?

matthewjh avatar Aug 30 '15 14:08 matthewjh

@matthewjh It's not a problem of performance at runtime. It's a problem of development. We convert old JS code to TS and actively add new types and interfaces. So the number of interfaces changes frequently and it's not very good idea to support them in two places.

Koloto avatar Aug 30 '15 15:08 Koloto