3

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

user888734
  • 3,797
  • 5
  • 36
  • 67

1 Answers1

1

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

basarat
  • 261,912
  • 58
  • 460
  • 511
  • This is bizarre! The above won't even compile for me in VS, but compiles absolutely fine in the TypeScript playground. The property 'setup' does not exist on value of type 'new(options?: any) => MyModel' – user888734 Jun 29 '13 at 13:43
  • Compiles in my VS. Which version are you using. I am on 0.9.0 – basarat Jun 29 '13 at 13:53
  • 1
    Aha! Now it all works! I was using 0.8.x and it wasn't happy about the static setup method. Now it works, and so does everything else. Thank you for your help. – user888734 Jun 29 '13 at 14:44
  • Thank you for the gargantuan bounty :) – basarat Jun 29 '13 at 14:52