Trust us! (those who tried and burned themselves), modules/namespaces best avoided when you can.
Using them, you can solve many uninteresting problems, such as
- compile temporary file ordering ( How to create the correct file order using typescript? )
- circular links ( Circular dependency issue with Typescript, CommonJS and Browserify )
- etc.
Also "neat" is controversial
If this can make you feel better than Java developers - a few years before Typescript even existed - many will import at the top of their files, and I hope their lifespan is not shorter than that of Javascript developers ( being one of them). More seriously, some IDEs, such as Webstorm (12 EAP), automatically handle the import for you and even stack them in an editor so that they do not "pollute" the presentation of your code.
What you are doing is somehow import * , rather than importing what you require, is controversial in terms of code design.
Isolation is generally better with external modules.
Now suppose your code is split into two: an API and an implementation, and you want to immediately import all the API definitions in the implementation classes to avoid multiple import statements.
In the API section, you can create an api.ts file that relays all ie
export * from 'interfaces/model/Model' export * from 'interfaces/model/Interfaces' export * from 'interfaces/model/Serializables' ...
Then, in the implementation classes, simply import a single api.ts file into the namespace, for example:
import * as api from '../api/api.ts'
Then you can access all exported APIs like api.List , api.MyModel , etc.
But since you are at it, why not go all the way and create an external module to define your APIs? :)
Library creation
Unfortunately, at the moment I can not find the final resource.
TL; DR to create a library:
- create
index.ts , which re-exports all the definitions you want to open in your library. - compile library files with the
--declaration flag to automatically generate typing - add a
typings entry to package.json , pointing to the generated index.d.ts file
To use the library:
- put it in the
node_modules folder like any other library - just
import * as mylib from 'mylib' : it automatically imports all exported definitions and type characters
There is a brief mention here
You can also see the Library and Usage paragraphs of what I wrote there.
If I find a better resource, I will update this answer