在 typescript 环境中使用 node 模块

Use node module in typescript environment

我一直在尝试在我的 angular 2.0 客户端中使用节点模块 'markdown' 和 'dustjs-helpers'。问题是我无法使用 typings 找到解决方案(这两个包在 typings 上都不可用)我想知道是否有办法在 angular 2.0.

中使用它们

我必须在客户端使用它们,因为我不能用很多请求使服务器过载。

您可以为这些库创建一个简单的 type definition 文件。

创建文件mytype.d.ts:

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

将此引用添加到您的 .ts 文件中":

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

确保路径正确。

更多详情:https://www.typescriptlang.org/docs/handbook/writing-declaration-files.html.