I am new to Typescript and module handling. In my project I am coding in Typescript for developing a browser library. I am therefore using AMD. Following is the tsconfig.json file.
{
"compilerOptions": {
"target": "ES5",
"outDir": "out",
"module": "amd"
},
"files": [
"src/main.ts",
"src/communication.ts",
...
]
}
File communication.ts is:
export module MyProj.DataExchange {
export interface Communication {
connect(uri: string): void;
close(): void;
status: int;
}
}
Referencing components from other files
I want to use Communication in main.ts:
import communication = require('./communication');
export module MyProj {
export class Communicator
implements communication.MyProj.DataExchange.Communication {
...
}
}
I would like to avoid using the whole signature communication.MyProj.DataExchange.Communication. So I tried something like:
import communication = require('./communication').MyProj.DataExchange;
But it did not work.
My questions
I have a feeling I am doing something wrong in here. Here my questions:
- Am I doing things the way they are supposed to be done?
- How to avoid using the whole name for an imported component?
- In case you might tell me not to use
module, I need to separate my components into namespaces. So how to correctly set namespaces in case I am doing it wrong?