Reputation: 12821
Please consider the following scenario: I am attempting to author typescript definitions for two commonJS modules, A and B. B has a dependency on A, and, for convenience, B exports A directly as a property B.A
so that the user does not need to explicitly require('A')
in their code.
My question is, how can I author the typescript definition of B so as to export A as a property of B? Here is what I have attempted:
A has various members which it exports:
export const foo = 'bar';
Then, in B I have tried:
import * as A from 'A';
export A;
and
import * as a from 'A';
export var A : a;
However, neither of these are valid typescript module definitions.
The goal is, in the typescript code which is consuming B, to be able to write:
import B = require('B');
console.log(B.A.foo);
What is the correct way to author B's module definition so that it exports A as a property of B?
Upvotes: 1
Views: 99
Reputation: 1672
A.ts
export let foo = 1;
B.d.ts
import * as A from "./A";
export {
A
}
usage
import B from "./B";
console.log(B.A.foo);
Upvotes: 1