Reputation: 117
Is is possible to export into the same module form 2 different typescript files?
I have:
module a1 {
export module a2 {
export module Topic1 {
export class Type1 {
constructor(public id: string) { }
}
export let Entity = new Type1("entity");
}
}
}
module a1 {
module a2 {
module Topic1 {
// how do I export something into a1.a2.Topic1 ?
export let Relation = new a1.a2.Topic1.Type1("relation");
}
}
function test1() {
// this works:
let v1 = a1.a2.Topic1.Entity;
// this show an error:
// Property 'Relation' does not exist on type 'typeof Topic1'.
let v2 = a1.a2.Topic1.Relation;
}
}
I've tried a few different approaches but could not get it to work.
The idea is here to use the top level module to distinguish between projects, and the inner/sub-modules for actual project modules and submodules. Is there a best practise when it comes to using typescript in large projects? Thanks.
EDIT 1: Updated the comment to reflect the intention - to export into the Topic1 rather than its parent.
Upvotes: 0
Views: 40
Reputation: 276239
A simplified sample of your desire:
module a1 {
export module a2 {
export module Topic1 {
// how do I export something into a1.a2 ?
}
}
}
Simple answer: No. You cannot export into a1.a2
unless you are in a1.a2
. In your case you are in a1.a2.Topic1
.
how do I export something into a1.a2.Topic1
Just make sure you export every level inside a1
module a1 {
export module a2 { // export here
export module Topic1 { // export here
export const foo = 123;f // export here
}
}
}
Upvotes: 1