打字稿无效?

时间:2012-12-06 15:38:15

标签: javascript typescript

我无法弄清楚为什么这个函数认为)从最后遗漏了。当我放置)时,它会创建一个自动执行的函数,并生成不是我想要的javascript。

作品

this.Events.off = (): any {
    var events = arguments[0],
        callback = arguments[1];
    if (typeof events === 'string' && typeof callback === 'function') {
        this._events.off.call(this._events, events, callback);
    }
    else if (typeof callback === 'function') {
        this._events.off.call(this._events, callback);
    }
};

错误

declare var $, Backbone;

export class WebControls {

    _events;
    Events;

    constructor (options? ) {

        this._events = $.extend({}, Backbone.Events);

        this.Events = {};

        this.Events.on = (events: string, cb: (event: any) => any) {
            this._events.on.apply(this._events, arguments);
        };

        this.Events.trigger = (eventName: string, ...args: any[]): any {
            this._events.trigger.apply(this._events, arguments);
        };

        this.Events.off = (events?: string, callback?: any) : any {
            if (typeof events === 'string' && typeof callback === 'function') {
                this._events.off.call(this._events, events, callback);
            } else if (typeof callback === 'function') {
                this._events.off.call(this._events, callback);
            }
        };
    }

}

screenshot of red squiggly compilation screenshots compilation screenshots compilation screenshots

我是否一味地忽略了一些明显的东西?

1 个答案:

答案 0 :(得分:3)

在屏幕截图代码中,您需要一个'function'关键字或参数列表后的胖箭头。