4

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 !

1 Answer 1

1

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 ;)

Sign up to request clarification or add additional context in comments.

2 Comments

Ok but have is the point ! If i use a namespace it's because i don't want to import all files everytime ! and when i reference my files into my index.ts i have an error " <file> is not a module " ...
You need to import them or reference them... Otherwhise how he can know that the file exist... When you develop in C# or Java you need using or import, for typescript it's the same

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.