From 8863daa0c31b4650b3a670d9a62ee36eee6e7644 Mon Sep 17 00:00:00 2001 From: "Omid K. Rad" Date: Mon, 26 Oct 2015 17:08:57 -0700 Subject: [PATCH 1/2] Add interfaces for ObjectHash, RoutesHash and EventsHash --- backbone/backbone-global.d.ts | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/backbone/backbone-global.d.ts b/backbone/backbone-global.d.ts index 734ba1b94..0a8e16961 100644 --- a/backbone/backbone-global.d.ts +++ b/backbone/backbone-global.d.ts @@ -65,6 +65,18 @@ declare module Backbone { reset?: boolean; } + interface ObjectHash { + [key: string]: any; + } + + interface RoutesHash { + [routePattern: string]: string | {(...urlParts: string[]): void}; + } + + interface EventsHash { + [selector: string]: string | {(eventObject: JQueryEventObject): void}; + } + class Events { on(eventName: string, callback?: Function, context?: any): any; off(eventName?: string, callback?: Function, context?: any): any; @@ -102,7 +114,7 @@ declare module Backbone { * For assigning an object hash, do it like this: this.defaults = { attribute: value, ... }; * That works only if you set it in the constructor or the initialize method. **/ - defaults(): any; + defaults(): ObjectHash; id: any; idAttribute: string; validationError: any; @@ -272,7 +284,7 @@ declare module Backbone { * For assigning routes as object hash, do it like this: this.routes = { "route": callback, ... }; * That works only if you set it in the constructor or the initialize method. **/ - routes: any; + routes: RoutesHash | any; constructor(options?: RouterOptions); initialize(options?: RouterOptions): void; @@ -310,7 +322,7 @@ declare module Backbone { interface ViewOptions { model?: TModel; // TODO: quickfix, this can't be fixed easy. The collection does not need to have the same model as the parent view. - collection?: Backbone.Collection; + collection?: Backbone.Collection; //was: Collection; el?: any; id?: string; className?: string; @@ -333,7 +345,7 @@ declare module Backbone { * For assigning events as object hash, do it like this: this.events = { "event:selector": callback, ... }; * That works only if you set it in the constructor or the initialize method. **/ - events(): any; + events(): EventsHash; $(selector: string): JQuery; model: TModel; @@ -353,7 +365,7 @@ declare module Backbone { render(): View; remove(): View; make(tagName: any, attributes?: any, content?: any): any; - delegateEvents(events?: any): any; + delegateEvents(events?: EventsHash): any; undelegateEvents(): any; _ensureElement(): void; From 029999da9e3329506f0e713d800d0be2e4bd34a2 Mon Sep 17 00:00:00 2001 From: "Omid K. Rad" Date: Mon, 26 Oct 2015 17:09:17 -0700 Subject: [PATCH 2/2] Add overload for Backbone.Events.on() --- backbone/backbone-global.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/backbone/backbone-global.d.ts b/backbone/backbone-global.d.ts index 0a8e16961..ae111aea0 100644 --- a/backbone/backbone-global.d.ts +++ b/backbone/backbone-global.d.ts @@ -79,6 +79,7 @@ declare module Backbone { class Events { on(eventName: string, callback?: Function, context?: any): any; + on(eventMap: EventsHash): any; off(eventName?: string, callback?: Function, context?: any): any; trigger(eventName: string, ...args: any[]): any; bind(eventName: string, callback: Function, context?: any): any;