0

How would I use the same typescript class or module in a client side javascript file and in a server side node.js file?

I found a solution here where you manually create the exports variable instead of using TypeScript's export keyword but then you lose the type information for the class when you include it in node.js with the require keyword.

4

1 回答 1

1

你可以投射require函数产生的东西,因为你知道它会是什么。

module Lib {
    export class Alpha {
        bravo: number = 1;
    }
}

// meanwhile back at the ranch
var _lib = <Lib> require("Lib");
var a = new _lib.Alpha();
于 2013-06-05T15:30:51.577 回答