Skip to content

Multiple export as namespace not merging in the same namespace #61942

Closed as not planned
@lmartorella

Description

@lmartorella

🔎 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

https://www.typescriptlang.org/dev/bug-workbench/?ts=5.8.3&multifile=true#code/PTAEAEDMEsBsFMB2BDAtvAXKW0BGBGAOgBNCAXAZwFgAoY+AY1mQCd5QBzWAe12VlABvWqFAp0FAA7IG7RBSEjRo+AA9J3FmVBNkFBQGF8Q0AF8l5mpbUatJy7RAQYCcZmx4ATCXLUa0VFtteVBIFm5UUAAiQmAcXG94ClQogG5aG01tPTE0JOlZMQp0mkytAF4ikscwKDgkPKx4xOSfSgz1LNB6XTYdZn1QA097WhrnercmvABmNr8AoKLQ8MiYuNnCJJSSsuyFNykZOWKOoMr5aponOtdGj1w57fmzrp7mPt1BgxnRmnHbg10FhkJJJL4amAADxsSDwNiIQrSMgAC3K63iRFIlCioGAAD5IaAYfA4QikchUejYs15riCUSSWSkBSqRjNtiKPTCf8aAxuPJtAxjBd4AB3IqEIwACgAlCV+YKdCNRRL5FLPHKFQKKELfqrJT8tbQgA

💻 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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    QuestionAn issue which isn't directly actionable in code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions