0

Can I export a namespace A with another namespace B in it? Something like:

// b.ts
export namespace B {
  export const val = 'val';
}
// a.ts
export namespace A {
  //... some thing import b as namespace 
}

--- above will be export as a module and depended by another project C;

// c.ts
import { B } from 'A';

const a = B.val;

And I hope ts show me 'namespace B' in C instead of 'import B', which seems to be impossible ;

another question is: if I can split namespace B into multi files when I export, like:

// b2.ts
export namespace B {
  export const val2 = 'val2';
}

and it can be imported in C

// c.ts
import { B } from 'A';

const b2 = B.val2;
Zotille
  • 113
  • 8

1 Answers1

1

I had the same problem, and finally came across this answer on the Typescript Github repo.

The work around is as follows:

// b.ts (no change here)
export namespace B {
  export const val = 'val';
}

in a.ts

// a.ts
import {B as _b} from './b.ts'
export namespace A {
  export import B = _b
}

And finally in C.ts

import { A } from './a.ts'
const b2 = A.B.val;

As for the second part of your question, i think this and this may help you out.

Dharman
  • 30,962
  • 25
  • 85
  • 135
chai_and_kaapi
  • 181
  • 1
  • 5