1

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?

3
  • The error indicates a syntax error. Which line in the sample you posted is line 40? Commented Apr 21, 2014 at 15:31
  • Remove the semi-colon from the end of the line you're pointing to. Commented Apr 21, 2014 at 16:00
  • The abstract keyword has now been added, v1.6: blogs.msdn.com/b/typescript/archive/2015/09/16/… Commented Sep 17, 2015 at 6:56

1 Answer 1

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

Try to delete semicolon here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.