gpt4 book ai didi

angular - TypeScript Path2D 类缺少字符串构造函数

转载 作者:太空狗 更新时间:2023-10-29 18:31:17 25 4
gpt4 key购买 nike

我正在尝试从 SVG 字符串路径创建 Path2D 对象。根据Path 2D documentation来自 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 没有 Path2D 类的字符串构造函数。

我该如何解决这个问题?我正在使用 Typescript 2.2.1

最佳答案

存在 Unresolved 错误 Path2D missing string construtor

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);

另见

关于angular - TypeScript Path2D 类缺少字符串构造函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43773190/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com