Domanda

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?

È stato utile?

Soluzione

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

Try to delete semicolon here

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top