我熟悉打字稿中的参考标签,但是没有一个明确打字的模块似乎真的在浏览器中本地工作,如果我使用' import'标签使intellisense工作它生成无关的代码用于创建模块(我假设与node.js一起使用?)因此我在浏览器中得到异常。
///<reference path='paper/paper.d.ts' />
//import paper = require('paper'); //This makes intellisense work
paper.setup(<HTMLCanvasElement>document.getElementById("#my-canvas"));
var path = new paper.Path();
path.strokeColor = 'black';
var start = new paper.Point(100, 100);
path.moveTo(start);
path.lineTo(start.add([200, -50]));
paper.view.draw();
这里是生成的文件,它保存了一个require语句......这在浏览器中没有任何意义。知道怎么不让这件事发生吗?
"use strict";
///<reference path='paper/paper.d.ts' />
Object.defineProperty(exports, "__esModule", { value: true });
var paper = require("paper"); //Garbage that causes exceptions
paper.setup(document.getElementById("#my-canvas"));
var path = new paper.Path();
path.strokeColor = 'black';
var start = new paper.Point(100, 100);
path.moveTo(start);
path.lineTo(start.add([200, -50]));
paper.view.draw();
//# sourceMappingURL=app.js.map
答案 0 :(得分:1)
您可以使用UMD,又称as namespace
技巧:
// custom-typings/paper.d.ts
import * from 'paper'
export as namespace paper
// tsconfig.json
{
"include": {
"custom-typings"
}
}