Reputation: 16845
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;
}
}
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.
I have a feeling I am doing something wrong in here. Here my questions:
module
, I need to separate my components into namespaces. So how to correctly set namespaces in case I am doing it wrong?Upvotes: 1
Views: 133
Reputation: 449
In Typescript 1.4 have been introduced Type Aliases.
Your code might be adapted to use aliases like this:
import communication = require('./communication')
type Communication = communication.MyProj.DataExchange.Communication;
export module MyProj {
export class Communicator
implements Communication {
...
}
}
Upvotes: 1