Skip to content Skip to sidebar Skip to footer

Use A Typescript Module/class In The Browser And In The Server (node.js)

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 export

Solution 1:

You can cast what comes out of the require function since you know what it's going to be.

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

// meanwhile back at the ranch
var _lib = <Lib> require("Lib");
var a = new _lib.Alpha();

Post a Comment for "Use A Typescript Module/class In The Browser And In The Server (node.js)"