From de92542c5512b34f95ab5d0b8f0c1a709675a970 Mon Sep 17 00:00:00 2001 From: Jared Pochtar Date: Mon, 19 Aug 2013 19:23:40 -0400 Subject: [PATCH] Router.routes, View.events, and Model.defaults -> method form As of typescript 0.9.1, fields are set after calling the super constructor, so if events, defaults, or routes are set to object literals, they will not be seen by backbone, and will not be bound. The cleanest way to fix this is to define them as methods which return an object hash, as the methods are already on the prototype chain when backbone looks for events/defaults/routes, and backbone supports either objects or functions that when called return objects. --- backbone/backbone.d.ts | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/backbone/backbone.d.ts b/backbone/backbone.d.ts index 99aec4e4b..0635a1247 100644 --- a/backbone/backbone.d.ts +++ b/backbone/backbone.d.ts @@ -86,14 +86,17 @@ declare module Backbone { sync(...arg: any[]): JQueryXHR; } - class Model extends ModelBase { + interface OptionalDefaults { + defaults?(): any; + } + + class Model extends ModelBase implements OptionalDefaults { static extend(properties: any, classProperties?: any): any; // do not use, prefer TypeScript's extend functionality attributes: any; changed: any[]; cid: string; - defaults: any; id: any; idAttribute: string; validationError: any; @@ -235,12 +238,14 @@ declare module Backbone { zip(...model: Model[]): Model[]; } - class Router extends Events { + interface OptionalRoutes { + routes?(): any; + } + + class Router extends Events implements OptionalRoutes { static extend(properties: any, classProperties?: any): any; // do not use, prefer TypeScript's extend functionality - routes: any; - constructor(options?: RouterOptions); initialize(options?: RouterOptions); route(route: string, name: string, callback?: (...parameter: any[]) => void ); @@ -283,7 +288,11 @@ declare module Backbone { attributes?: any[]; } - class View extends Events { + interface OptionalEvents { + events?(): any; + } + + class View extends Events implements OptionalEvents { static extend(properties: any, classProperties?: any): any; // do not use, prefer TypeScript's extend functionality @@ -299,7 +308,7 @@ declare module Backbone { cid: string; className: string; tagName: string; - events: any; + options: any; el: any; $el: JQuery;