Search code examples
angularnode-modulestypescript-typingsdust-helpers

Use node module in typescript environment


I've been trying to use the node modules 'markdown' and 'dustjs-helpers' in my angular 2.0 client side. The thing is that I couldn't reach a solution using typings (both packages are not available on typings) and I wonder if there is a way to use them in angular 2.0.

I have to use them on the client side because I can't overload the server with many requests.


Solution

  • You can create a simple type definition file for those libraries.

    Create a file mytype.d.ts:

    interface Widget {
        render(): void;
        getInfo(): void;
    }
    

    Add this reference to your .ts file":

    ///<reference path="mytype.d.ts" /> 
    

    Make sure the path is correct.

    More details: https://www.typescriptlang.org/docs/handbook/writing-declaration-files.html.