문제

I am trying to compile this typescript file to Javascript but I'm getting an error:

File:

/**
 * 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

}

Error:

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

All other typescript files in my project are compiling fine. In this file I'm trying to create an abstract class which is difficult because there are no abstract classes in Typescript. I want to be able to inherit other classes from this class - so I've created the load() function which would be overridden in the classes that extend it. Is this appropriate?

도움이 되었습니까?

해결책

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

Try to delete semicolon here

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top