Typescript fabricjs.d.ts真的缺少动画功能吗?
我对织物和打字稿都不熟悉。现在我正试图使用这个库,我遇到了一个奇怪的错误。在我的代码中,我尝试这样做:Typescript fabricjs.d.ts真的缺少动画功能吗?,typescript,fabricjs,Typescript,Fabricjs,我对织物和打字稿都不熟悉。现在我正试图使用这个库,我遇到了一个奇怪的错误。在我的代码中,我尝试这样做: var rect = new fabric.Rect(); rect.animate('angle', '-=5', { onChange: this.canvas.renderAll.bind(this.canvas) }); 但是它告诉我,“属性animate”在类型ioobject上不存在。当我检查定义文件时,我看到fabric.util中只有一
var rect = new fabric.Rect();
rect.animate('angle', '-=5', {
onChange: this.canvas.renderAll.bind(this.canvas)
});
但是它告诉我,“属性animate”在类型ioobject上不存在
。当我检查定义文件时,我看到fabric.util中只有一个名为animate的函数
var util: {
addClass(element: HTMLElement, className: string);
addListener(element, eventName: string, handler);
animate(options: {
onChange?: (value: number) => void;
onComplete?: () => void;
startValue?: number;
endValue?: number;
byValue?: number;
easing?: (currentTime, startValue, byValue, duration) => number;
duration?: number;
});
createClass(parent, properties);
... }
我从你那里得到了定义
是真的不完整还是我遗漏了一些重要的东西?我不是专家,但我看了一下,我认为你是对的 看起来所有fabric对象都应该获得animate方法,但在typescript定义文件中,IOObject没有指定animate方法,因此任何对象都不会获得包含Direct的方法,Direct是/扩展IOObject 我试过这个,效果很好: 在fabricjs.d.ts中找到IOObject声明(搜索“接口IOObject”),然后添加下面的行
export interface IObject extends IObservable {
//this line:
animate(property: string, value: any, options?: any): IObject;
保存.d.ts文件,它应该适用于您的示例,尽管参数可能不是理想的类型
希望有帮助。定义文件缺少边缘函数的情况并不少见。然而,对于图书馆作者来说,错过文献更为常见。GitHub上的DefinitelyTyped集合只由贡献者组合在一起,到目前为止,只查看了1个人()对fabricjs有所帮助,而且仅在去年12月。越来越多的人转向TypeScript,并且是fabric js用户,希望会有更多的ContirButters让TypeScript def得到全面覆盖。谢谢John。我添加了你的建议,效果非常好。每当我遇到遗漏的东西时,我会在定义中添加更多的东西。我可能很快也会将我的更改添加到回购协议中。