1

Lets say I have 2 classes, A and B, implemented in 2 different files: A.ts and B.ts (both exporting just the class instance implemented in them).

I would like to export them both in a third file C.ts:

import A from "./A";
import B from "./B";
export module mymodule {
    export A;
    export B;
}

Unfortunately the above doesn't compile..

geochr
  • 241
  • 1
  • 3
  • 15
  • Possible duplicate of [Re-exporting ES6 modules in TS 1.7?](http://stackoverflow.com/questions/34557587/re-exporting-es6-modules-in-ts-1-7) – C Snover Jan 28 '16 at 15:57
  • @geochr Same issue as yours, wonder if you found a solution. – Shyamal Parikh Jan 24 '17 at 21:06
  • @ShyamalParikh Yea we did Inside the exported mymodule you go : export type AExported = A; export const AExported = A; This allows you to export A as mymodule.AExported – geochr Mar 15 '17 at 15:05

1 Answers1

1

In C.ts, do

export * from './A'
export * from './B'

When importing C, definitions from A and B will be available too.

There is one caveat: you cannot re-export default exports.

Bruno Grieder
  • 28,128
  • 8
  • 69
  • 101
  • 1
    Thanks for your answer. I am looking to export A and B in a new namespace though . – geochr Jan 28 '16 at 08:58
  • OK. Not sure what your objective is but have you read this (last sentence)?: https://basarat.gitbooks.io/typescript/content/docs/project/namespaces.html. You should not mix namespaces and external modules... and actually most likely not use namespaces at all. In `D` you can `import * as ns from './C'` and `ns` is your namespace – Bruno Grieder Jan 28 '16 at 09:22
  • 1
    I have several classes that I want to organize into modules via a single file. So C would actually have to export multiple modules. Not sure if this is possible now. – geochr Jan 28 '16 at 09:45