Description
🔎 Search Terms
export as namespace, ambient namespace, module
🕗 Version & Regression Information
- This is the behavior in every version 5.x I tried, and I reviewed the FAQ for entries about "export as namespace" but I. didn't find anything relevant.
⏯ Playground Link
💻 Code
// @filename: lib1.d.ts
declare global {
namespace ns {
export class C1 { }
}
}
export { }
// @filename: lib2.d.ts
import ns from "./lib2.esm";
export as namespace ns;
export= ns;
// @filename: lib2.esm.d.ts
export declare class C2 { }
// @filename: lib3.d.ts
import ns from "./lib3.esm";
export as namespace ns;
export= ns;
// @filename: lib3.esm.d.ts
export declare class C3 { }
// @filename: app.ts
/// <reference path="./lib1.d.ts" />
/// <reference path="./lib2.d.ts" />
/// <reference path="./lib3.d.ts" />
const c1 = new ns.C1();
const c2 = new ns.C2();
const c3 = new ns.C3();
🙁 Actual behavior
Property 'C3' does not exist on type 'typeof import("/lib2.esm")'.
Only the ambient module (lib1) and the first "export as namespace ns" instance (lib2) are merged in the target ambient namespace.
It doesn't find the symbols declared in lib3
, or any other additional file that uses "export as namespace ns".
🙂 Expected behavior
All declaration files that uses "export as namespace ns" are expected to correctly merge in the same namespace, not only the first one.
Additional information about the issue
A very little documentation is around about the "export as namespace" feature.
We are converting our codebase migrating from ambient module to ESM, and we need to phase the migration one module at a time, still having the possibility to use the code as ambient until the full migration completes.
Even a different workaround is more than welcome!