Closed
Description
Re-exports of external modules with no public members are erased from the generated JS for ES5 targets. This causes problems in scenarios where the module is used to extend some class by patching the prototype (see #6213 and #6022).
The ultimate goal is to be able to do the following:
// a.ts
export class A { }
// b.ts
import {A} from './a';
A.prototype.foo = function () { };
declare module './a' {
interface A { foo(): void; }
}
// c.ts
import {A} from './a';
A.prototype.bar = function () { };
declare module './a' {
interface A { bar(): void; }
}
// all.ts
export {A} from './a';
export * from './b';
export * from './c';
Once this is built and distributed as a set of JS and definition files, the user should be able to do:
import {A} from 'somemodule/a';
import 'somemodule/all';
var a = new A();
a.foo();
a.bar();
Currently, this compiles without errors, but produces the following output for all.js
:
"use strict";
var a_1 = require('./a');
exports.A = a_1.A;
You can see that ./b
and ./c
are not imported, which results in the prototype patches for A
being unavailable at runtime. The user will therefore get the following exception:
TypeError: a.foo is not a function
Hopefully I'm not misusing the feature here.