From bcc1a8bb52634555680bbf456b44d0f1e4ade6a6 Mon Sep 17 00:00:00 2001 From: Boris Yankov Date: Wed, 19 Jun 2013 04:33:08 +0300 Subject: [PATCH] Merge pull request #613 from JudahGabriel --- knockout/knockout.d.ts | 138 +++++++++++++---------------------------- 1 file changed, 43 insertions(+), 95 deletions(-) diff --git a/knockout/knockout.d.ts b/knockout/knockout.d.ts index c4de6b8734..ba9e743039 100644 --- a/knockout/knockout.d.ts +++ b/knockout/knockout.d.ts @@ -21,29 +21,29 @@ interface KnockoutComputedFunctions extends KnockoutSubscribableFunctions { interface KnockoutObservableFunctions extends KnockoutSubscribableFunctions { } -interface KnockoutObservableArrayFunctions extends KnockoutObservableFunctions { +interface KnockoutObservableArrayFunctions extends KnockoutObservableFunctions { // General Array functions - indexOf(searchElement, fromIndex?: number): number; - slice(start: number, end?: number): any[]; - splice(start: number): any[]; - splice(start: number, deleteCount: number, ...items: any[]): any[]; + indexOf(searchElement: T, fromIndex?: number): number; + slice(start: number, end?: number): T[]; + splice(start: number): T[]; + splice(start: number, deleteCount: number, ...items: T[]): T[]; pop(); - push(...items: any[]): void; + push(...items: T[]): void; shift(); - unshift(...items: any[]): number; - reverse(): any[]; + unshift(...items: T[]): number; + reverse(): T[]; sort(): void; sort(compareFunction): void; // Ko specific - replace(oldItem: any, newItem: any): void; + replace(oldItem: T, newItem: T): void; - remove(item): any[]; - removeAll(items: any[]): any[]; - removeAll(): any[]; + remove(item): T[]; + removeAll(items: T[]): T[]; + removeAll(): T[]; - destroy(item): void; - destroyAll(items: any[]): void; + destroy(item: T): void; + destroyAll(items: T[]): void; destroyAll(): void; } @@ -61,110 +61,58 @@ interface KnockoutSubscription extends KnockoutSubscribableFunctions { interface KnockoutComputedStatic { fn: KnockoutComputedFunctions; - (): KnockoutComputed; - (func: Function, context?: any, options?: any): KnockoutComputed; - (def: KnockoutComputedDefine): KnockoutComputed; - (options?: any): KnockoutComputed; + (): KnockoutComputed; + (func: () => T, context?: any): KnockoutComputed; + (def: KnockoutComputedDefine): KnockoutComputed; + (options?: any): KnockoutComputed; } -interface KnockoutComputed extends KnockoutObservableAny, KnockoutComputedFunctions { +interface KnockoutComputed extends KnockoutComputedFunctions { + (): T; + (value: T): void; + + subscribe(callback: (newValue: T) => void, target?:any, topic?: string): KnockoutSubscription; + notifySubscribers(valueToWrite: T, topic?: string); } interface KnockoutObservableArrayStatic { - fn: KnockoutObservableArrayFunctions; - - (): KnockoutObservableArray; - (value: any[]): KnockoutObservableArray; - - new(): KnockoutObservableArray; - new(value: any[]): KnockoutObservableArray; + fn: KnockoutObservableArrayFunctions; + + (): KnockoutObservableArray; + (value: T[]): KnockoutObservableArray; } -interface KnockoutObservableArray extends KnockoutObservableArrayFunctions { - (): any[]; - (value: any[]): void; +interface KnockoutObservableArray extends KnockoutObservableArrayFunctions { + (): T[]; + (value: T[]): void; - subscribe(callback: (newValue: any[]) => void, target?:any, topic?: string): KnockoutSubscription; - notifySubscribers(valueToWrite: any[], topic?: string); + subscribe(callback: (newValue: T[]) => void, target?:any, topic?: string): KnockoutSubscription; + notifySubscribers(valueToWrite: T[], topic?: string); } interface KnockoutObservableStatic { fn: KnockoutObservableFunctions; - (value: string): KnockoutObservableString; - (value: Date): KnockoutObservableDate; - (value: number): KnockoutObservableNumber; - (value: bool): KnockoutObservableBool; - (value?: any): KnockoutObservableAny; - - new(value: string): KnockoutObservableString; - new(value: Date): KnockoutObservableDate; - new(value: number): KnockoutObservableNumber; - new(value: bool): KnockoutObservableBool; - new(value?: any): KnockoutObservableAny; + (value: T): KnockoutObservable; } /** use as method to get/set the value */ interface KnockoutObservableBase extends KnockoutObservableFunctions { getSubscriptionsCount(): number; } + +interface KnockoutObservable extends KnockoutObservableBase { + (): T; + (value: T): void; -/** use as method to get/set the value -can cast to a more appropriate (typed) interface such as KnockoutObservableString or KnockoutObservableNumber -*/ -interface KnockoutObservableAny extends KnockoutObservableBase { - - (): any; - (value): void; - - subscribe(callback: (newValue: any) => void, target?:any, topic?: string): KnockoutSubscription; - notifySubscribers(valueToWrite, topic?: string); + subscribe(callback: (newValue: T) => void, target?:any, topic?: string): KnockoutSubscription; + notifySubscribers(valueToWrite: T, topic?: string); } -interface KnockoutObservableString extends KnockoutObservableBase { - (): string; - (value: string): void; - - subscribe(callback: (newValue: string) => void, target?:any, topic?: string): KnockoutSubscription; - notifySubscribers(valueToWrite: string, topic?: string); -} - -interface KnockoutObservableObject extends KnockoutObservableBase { - (): {}; - (value: {}): void; - - subscribe(callback: (newValue: {}) => void , target?: any, topic?: string): KnockoutSubscription; - notifySubscribers(valueToWrite: {}, topic?: string); -} - -interface KnockoutObservableNumber extends KnockoutObservableBase { - (): number; - (value: number): void; - - subscribe(callback: (newValue: number) => void, target?:any, topic?: string): KnockoutSubscription; - notifySubscribers(valueToWrite: number, topic?: string); -} - -interface KnockoutObservableBool extends KnockoutObservableBase { - (): bool; - (value: bool): void; - - subscribe(callback: (newValue: bool) => void, target?:any, topic?: string): KnockoutSubscription; - notifySubscribers(valueToWrite: bool, topic?: string); -} - -interface KnockoutObservableDate extends KnockoutObservableBase { - (): Date; - (value: Date): void; - - subscribe(callback: (newValue: Date) => void, target?:any, topic?: string): KnockoutSubscription; - notifySubscribers(valueToWrite: Date, topic?: string); -} - -interface KnockoutComputedDefine { - read(): any; - write(any); +interface KnockoutComputedDefine { + read(): T; + write(T); } interface KnockoutBindingContext {