fabricjs.d.ts 真的缺少动画功能吗?

is fabricjs.d.ts really missing animate function?

我对 fabric 和 typescript 都不熟悉。现在我正在尝试使用该库,但遇到了一个奇怪的错误。在我的代码中,我尝试这样做:

    var rect = new fabric.Rect();
    rect.animate('angle', '-=5', {
        onChange: this.canvas.renderAll.bind(this.canvas)
    });

但它告诉我 'Property animate does not exist on type IObject'。当我检查定义文件时,我看到 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);
    ... }

我从 https://github.com/borisyankov/DefinitelyTyped/blob/master/fabricjs/fabricjs.d.ts

它真的不完整还是我遗漏了什么重要的东西?

我不是专家,但我看了看,我认为你是对的。

看起来所有的织物对象都应该获得 animate 方法,但是在 typescript 定义文件中,IObject 没有指定 animate 方法,因此没有对象会获得包括 IRect 在内的方法 is/extends IObject.

我试过了,效果很好:

在 fabricjs.d.ts 中找到 IObject 声明(搜索 'interface IObject'),然后添加下面的行。

export interface IObject extends IObservable {

    //this line:
   animate(property: string, value: any, options?: any): IObject;

保存 .d.ts 文件,它应该适用于您的示例,但参数可能不是理想的类型。

希望对您有所帮助。