Question

I've used Backbone Relational before, but not with Typescript, and I'm having trouble getting started:

/// <reference path="../Typings/backbone.d.ts"/>
/// <reference path="../Typings/backbone.relational.d.ts"/>

module Application.Models {
    export class Entity extends Backbone.RelationalModel {
        constructor(options?) {
            super(options);
        }
    }
}


var e = new Models.Entity()

This throws an error:

Uncaught TypeError: Object function Entity() {
                    _super.call(this);
        } has no method 'initializeModelHierarchy'

UPDATE:

I found this in the Backbone Relational docs that says that setup() will not be automatically called when using CoffeeScript syntax. Could this be related to my Typescript issue? If so, where in my typescript do you think I could call setup?

http://backbonerelational.org/#RelationalModel-setup

Was it helpful?

Solution

The proper way of setting up an entity according to Backbone documentation would be:

declare module Backbone{
    export class RelationalModel{
        constructor(options?:any);
        static setup():any;
    }   
}

class MyModel extends Backbone.RelationalModel {
    constructor(options?) {
        super(options);
    }
}

MyModel.setup();

var x = new MyModel();

TypeScript Playground And JsFiddle

Based on docs: http://backbonerelational.org/#RelationalModel-setup

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top