无法在TypeScript项目中使用Path2D [英] Using Path2D in a TypeScript project is not resolved

查看:149
本文介绍了无法在TypeScript项目中使用Path2D的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用新的 Path2D API在TypeScript项目中,但在lib.es6.d.ts中看不到它,使用此功能的最佳方法是什么?有人有Path2D的d.ts文件吗?

I want to use the new Path2D api in a TypeScript project but I don't see it in lib.es6.d.ts What is my best course of action to use this? Does anyone have a d.ts file for Path2D?

推荐答案

我花了一些时间,我为您做了声明:

I took me some time, and I made the Declaration for you:

我已经按照相同的标准TypeScript在lib.d.ts内部定义其接口的方式进行了此操作. 请注意,您可以轻松地将此代码扩展为将来的功能,如果愿意,我希望在此处对其进行更新.

I've done this following the same standard TypeScript defines its interfaces internally in lib.d.ts.
Note that you can extend this code easily for future features, and if you do I would love to see it updated here.

Path2D.d.ts (示例:

var canvas: HTMLCanvasElement = <HTMLCanvasElement>document.getElementById("canvas");
var ctx = canvas.getContext("2d");

var path1 = new Path2D();
path1.rect(10, 10, 100, 100);

var path2 = new Path2D(path1);
path2.moveTo(220, 60);
path2.arc(170, 60, 50, 0, 2 * Math.PI);

var m = (<SVGSVGElement>document.createElementNS("http://www.w3.org/2000/svg", "svg")).createSVGMatrix();
m.a = 1; m.b = 0;
m.c = 0; m.d = 1;
m.e = 300; m.f = 0;
path2.addPath(path1, m);

ctx.stroke(path1);
ctx.fill(path2);

这篇关于无法在TypeScript项目中使用Path2D的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆