Angular TypeScript Path2D类缺少字符串构造函数
我正在尝试从SVG字符串路径创建Path2D对象。根据Mozilla提供的,可以传递字符串路径作为参数,但是,当我在代码中尝试时,Webstorm IDE会显示以下错误:Angular TypeScript Path2D类缺少字符串构造函数,angular,typescript,svg,ionic2,Angular,Typescript,Svg,Ionic2,我正在尝试从SVG字符串路径创建Path2D对象。根据Mozilla提供的,可以传递字符串路径作为参数,但是,当我在代码中尝试时,Webstorm IDE会显示以下错误: TS2345: Argument of type "" is not assignable to parameter of type 'Path2D' 我尝试执行的代码是: let p = new Path2D('M10 10 h 80 v 80 h -80 Z'); 我发现声明Path2D的lib.d.ts没有Path2
TS2345: Argument of type "" is not assignable to parameter of type 'Path2D'
我尝试执行的代码是:
let p = new Path2D('M10 10 h 80 v 80 h -80 Z');
我发现声明Path2D的lib.d.ts没有Path2D类的字符串构造函数
我怎样才能解决这个问题?我使用的是Typescript 2.2.1存在开放性错误
Wokraround正在创建您自己的类型
interface Path2DConstructor {
new (): Path2D;
new (d: string): Path2D;
new (path: Path2D): Path2D;
prototype: Path2D;
}
declare var Path2D: Path2DConstructor;
var p = new Path2D('M10 10 h 80 v 80 h -80 Z');
ctx.fill(p);
另见