diff --git a/types/knockout/index.d.ts b/types/knockout/index.d.ts index 40464a3bd8..533f2adfc5 100644 --- a/types/knockout/index.d.ts +++ b/types/knockout/index.d.ts @@ -4,23 +4,22 @@ // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -interface KnockoutSubscribableFunctions { - [key: string]: KnockoutBindingHandler | undefined; - - notifySubscribers(valueToWrite?: T, event?: string): void; +interface KnockoutExtensionFunctions { + [key: string]: any; } -interface KnockoutComputedFunctions { - [key: string]: KnockoutBindingHandler | undefined; +interface KnockoutSubscribableFunctions extends KnockoutExtensionFunctions { + notifySubscribers(valueToWrite?: T, event?: string): void; } -interface KnockoutObservableFunctions { - [key: string]: KnockoutBindingHandler | undefined; - - equalityComparer(a: any, b: any): boolean; +interface KnockoutComputedFunctions extends KnockoutExtensionFunctions { } -interface KnockoutObservableArrayFunctions { +interface KnockoutObservableFunctions extends KnockoutExtensionFunctions { + equalityComparer(a: any, b: any): boolean; +} + +interface KnockoutObservableArrayFunctions extends KnockoutExtensionFunctions { // General Array functions indexOf(searchElement: T, fromIndex?: number): number; slice(start: number, end?: number): T[]; @@ -35,8 +34,6 @@ interface KnockoutObservableArrayFunctions { sort(compareFunction: (left: T, right: T) => number): KnockoutObservableArray; // Ko specific - [key: string]: KnockoutBindingHandler | undefined; - replace(oldItem: T, newItem: T): void; remove(item: T): T[]; @@ -57,16 +54,16 @@ interface KnockoutSubscribableStatic { } interface KnockoutSubscription { - dispose(): void; + dispose(): void; } interface KnockoutSubscribable extends KnockoutSubscribableFunctions { subscribe(callback: (newValue: T) => void, target: any, event: "beforeChange"): KnockoutSubscription; - subscribe(callback: (newValue: T) => void, target?: any, event?: "change"): KnockoutSubscription; - subscribe(callback: (newValue: TEvent) => void, target: any, event: string): KnockoutSubscription; + subscribe(callback: (newValue: T) => void, target?: any, event?: "change"): KnockoutSubscription; + subscribe(callback: (newValue: TEvent) => void, target: any, event: string): KnockoutSubscription; - extend(requestedExtenders: { [key: string]: any; }): KnockoutSubscribable; - getSubscriptionsCount(): number; + extend(requestedExtenders: { [key: string]: any; }): KnockoutSubscribable; + getSubscriptionsCount(): number; } interface KnockoutComputedStatic { @@ -78,11 +75,11 @@ interface KnockoutComputedStatic { } interface KnockoutComputed extends KnockoutObservable, KnockoutComputedFunctions { - fn: KnockoutComputedFunctions; + fn: KnockoutComputedFunctions; - dispose(): void; - isActive(): boolean; - getDependenciesCount(): number; + dispose(): void; + isActive(): boolean; + getDependenciesCount(): number; extend(requestedExtenders: { [key: string]: any; }): KnockoutComputed; } @@ -108,23 +105,23 @@ interface KnockoutObservableStatic { } interface KnockoutObservable extends KnockoutSubscribable, KnockoutObservableFunctions { - (): T; - (value: T | null): void; + (): T; + (value: T | null): void; - peek(): T; - valueHasMutated?:{(): void;}; - valueWillMutate?:{(): void;}; + peek(): T; + valueHasMutated?:{(): void;}; + valueWillMutate?:{(): void;}; extend(requestedExtenders: { [key: string]: any; }): KnockoutObservable; } interface KnockoutComputedDefine { - read(): T; - write? (value: T): void; - disposeWhenNodeIsRemoved?: Node; - disposeWhen? (): boolean; - owner?: any; - deferEvaluation?: boolean; - pure?: boolean; + read(): T; + write? (value: T): void; + disposeWhenNodeIsRemoved?: Node; + disposeWhen? (): boolean; + owner?: any; + deferEvaluation?: boolean; + pure?: boolean; } interface KnockoutBindingContext { @@ -189,10 +186,10 @@ interface KnockoutBindingHandlers { uniqueName: KnockoutBindingHandler; // Rendering templates - template: KnockoutBindingHandler; + template: KnockoutBindingHandler; - // Components (new for v3.2) - component: KnockoutBindingHandler; + // Components (new for v3.2) + component: KnockoutBindingHandler; } interface KnockoutMemoization { @@ -217,12 +214,12 @@ interface KnockoutVirtualElements { interface KnockoutExtenders { throttle(target: any, timeout: number): KnockoutComputed; - notify(target: any, notifyWhen: string): any; + notify(target: any, notifyWhen: string): any; - rateLimit(target: any, timeout: number): any; - rateLimit(target: any, options: { timeout: number; method?: string; }): any; + rateLimit(target: any, timeout: number): any; + rateLimit(target: any, options: { timeout: number; method?: string; }): any; - trackArrayChanges(target: any): any; + trackArrayChanges(target: any): any; } // @@ -352,20 +349,20 @@ interface KnockoutTemplateSourcesDomElement { } interface KnockoutTemplateAnonymous extends KnockoutTemplateSourcesDomElement { - nodes(): any; - nodes(value: any): void; + nodes(): any; + nodes(value: any): void; } interface KnockoutTemplateSources { domElement: { - prototype: KnockoutTemplateSourcesDomElement - new (element: Element): KnockoutTemplateSourcesDomElement + prototype: KnockoutTemplateSourcesDomElement + new (element: Element): KnockoutTemplateSourcesDomElement }; anonymousTemplate: { - prototype: KnockoutTemplateAnonymous; - new (element: Element): KnockoutTemplateAnonymous; + prototype: KnockoutTemplateAnonymous; + new (element: Element): KnockoutTemplateAnonymous; }; } @@ -412,26 +409,26 @@ interface KnockoutStatic { utils: KnockoutUtils; memoization: KnockoutMemoization; - bindingHandlers: KnockoutBindingHandlers; - getBindingHandler(handler: string): KnockoutBindingHandler; + bindingHandlers: KnockoutBindingHandlers; + getBindingHandler(handler: string): KnockoutBindingHandler; virtualElements: KnockoutVirtualElements; extenders: KnockoutExtenders; applyBindings(viewModelOrBindingContext?: any, rootNode?: any): void; - applyBindingsToDescendants(viewModelOrBindingContext: any, rootNode: any): void; - applyBindingAccessorsToNode(node: Node, bindings: (bindingContext: KnockoutBindingContext, node: Node) => {}, bindingContext: KnockoutBindingContext): void; - applyBindingAccessorsToNode(node: Node, bindings: {}, bindingContext: KnockoutBindingContext): void; - applyBindingAccessorsToNode(node: Node, bindings: (bindingContext: KnockoutBindingContext, node: Node) => {}, viewModel: any): void; - applyBindingAccessorsToNode(node: Node, bindings: {}, viewModel: any): void; + applyBindingsToDescendants(viewModelOrBindingContext: any, rootNode: any): void; + applyBindingAccessorsToNode(node: Node, bindings: (bindingContext: KnockoutBindingContext, node: Node) => {}, bindingContext: KnockoutBindingContext): void; + applyBindingAccessorsToNode(node: Node, bindings: {}, bindingContext: KnockoutBindingContext): void; + applyBindingAccessorsToNode(node: Node, bindings: (bindingContext: KnockoutBindingContext, node: Node) => {}, viewModel: any): void; + applyBindingAccessorsToNode(node: Node, bindings: {}, viewModel: any): void; applyBindingsToNode(node: Node, bindings: any, viewModelOrBindingContext?: any): any; subscribable: KnockoutSubscribableStatic; observable: KnockoutObservableStatic; - computed: KnockoutComputedStatic; - pureComputed(evaluatorFunction: () => T, context?: any): KnockoutComputed; - pureComputed(options: KnockoutComputedDefine, context?: any): KnockoutComputed; + computed: KnockoutComputedStatic; + pureComputed(evaluatorFunction: () => T, context?: any): KnockoutComputed; + pureComputed(options: KnockoutComputedDefine, context?: any): KnockoutComputed; observableArray: KnockoutObservableArrayStatic; @@ -447,9 +444,9 @@ interface KnockoutStatic { cleanNode(node: Element): Element; renderTemplate(template: Function, viewModel: any, options?: any, target?: any, renderMode?: any): any; renderTemplate(template: string, viewModel: any, options?: any, target?: any, renderMode?: any): any; - unwrap(value: KnockoutObservable | T): T; + unwrap(value: KnockoutObservable | T): T; - computedContext: KnockoutComputedContext; + computedContext: KnockoutComputedContext; ////////////////////////////////// // templateSources.js @@ -557,10 +554,10 @@ interface KnockoutStatic { ///////////////////////////////// - bindingProvider: { - instance: KnockoutBindingProvider; - new (): KnockoutBindingProvider; - } + bindingProvider: { + instance: KnockoutBindingProvider; + new (): KnockoutBindingProvider; + } ///////////////////////////////// // selectExtensions.js @@ -599,15 +596,15 @@ interface KnockoutStatic { } interface KnockoutBindingProvider { - nodeHasBindings(node: Node): boolean; - getBindings(node: Node, bindingContext: KnockoutBindingContext): {}; - getBindingAccessors?(node: Node, bindingContext: KnockoutBindingContext): { [key: string]: string; }; + nodeHasBindings(node: Node): boolean; + getBindings(node: Node, bindingContext: KnockoutBindingContext): {}; + getBindingAccessors?(node: Node, bindingContext: KnockoutBindingContext): { [key: string]: string; }; } interface KnockoutComputedContext { - getDependenciesCount(): number; - isInitial: () => boolean; - isSleeping: boolean; + getDependenciesCount(): number; + isInitial: () => boolean; + isSleeping: boolean; } // @@ -688,5 +685,5 @@ interface KnockoutComponents { declare var ko: KnockoutStatic; declare module "knockout" { - export = ko; + export = ko; } diff --git a/types/knockout/test/index.ts b/types/knockout/test/index.ts index ba96f6863f..e3f7820f94 100644 --- a/types/knockout/test/index.ts +++ b/types/knockout/test/index.ts @@ -1,4 +1,4 @@ - +/// /// declare var $; @@ -723,4 +723,20 @@ function observableArrayEventsTests() { count--; }); }, null, "arrayChange"); +} + +interface MySubscribable extends KnockoutSubscribable { + isBeautiful?: boolean; +} + +interface MyObservable extends KnockoutObservable { + isBeautiful?: boolean; +} + +interface MyObservableArray extends KnockoutObservableArray { + isBeautiful?: boolean; +} + +interface MyComputed extends KnockoutComputed { + isBeautiful?: boolean; } \ No newline at end of file