无法将typescript文件编译为Javascript

时间:2014-04-21 14:59:30

标签: typescript

我正在尝试将此打字稿文件编译为Javascript但我收到错误:

文件:

/**
 * Views
 */

/// <reference path="../typescriptDefinitions/main.d.ts" />

class XView extends Backbone.View {

//Template for defining the html view
template:(data:any) => string = null;
templateLocation:string;

constructor(options, survey:Backbone.Collection, div:JQuery) {
    super(options);
    this.$el = div;
    this.collection = survey;
}

render() {
    var self = this;
    if (this.template == null) {
        require(["text!" + this.templateLocation],
            function (html) {
                this.template = _.template(html);
                self.load();
            });
    } else {
        this.load();
    }
    this.delegateEvents();
    return this;
}

load(){}; // This is the line the error is pointing to

}

错误:

views.ts(40,13): error TS1008: Unexpected token; 'constructor,
 function, accessor or variable' expected.

我项目中的所有其他打字稿文件编译正常。在这个文件中,我试图创建一个很难的抽象类,因为在Typescript中没有抽象类。我希望能够从这个类继承其他类 - 所以我创建了load()函数,该函数将在扩展它的类中被覆盖。这个合适吗?

1 个答案:

答案 0 :(得分:3)

load(){}; // This is the line the error is pointing to

尝试删除分号