Clowning
Clowning

Reputation: 179

TypeScript Multiple files same namespace

i'm working on a personal project with Typescript.

To have a nice code and expendable code i want to split my code like that => One class One file, using namespace or module, i didnt see the difference !

But how can i call one file et be able to select all class which are inside this namespace ?

I had take a look into StackOverflow database but i haven't found anything !

For example:

// FileOne.ts
namespace Controllers {
  export class A {}
}

// FileTwo.ts
namespace Controllers {
  export class B {}
}

// index.ts
namespace App {
  constructor() {
    new Controllers.B();
    new Controllers.A();
  }
}

So if you have an idea ?

Thanks !

Upvotes: 4

Views: 3151

Answers (1)

OrcusZ
OrcusZ

Reputation: 3660

Namespaces are built for that, you just need to reference all the files you need into your index.ts.

Typescript transpiler & Visual Studio Code are build in TypeScript, So you can have a look into the code in GitHub ( TypeScript | VSCode ), you will learn a lot ;)

Upvotes: 1

Related Questions