From d8eb310220768f843720813ed821f04eedd3e4f9 Mon Sep 17 00:00:00 2001 From: Mathias Lorenzen Date: Mon, 26 Feb 2018 08:53:58 +0100 Subject: [PATCH 1/3] more fixes. --- types/knockout/index.d.ts | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/types/knockout/index.d.ts b/types/knockout/index.d.ts index 570f61d80b..54255c1c76 100644 --- a/types/knockout/index.d.ts +++ b/types/knockout/index.d.ts @@ -409,9 +409,18 @@ interface KnockoutTasks { } ///////////////////////////////// +type KnockoutObservableTypeParameter = { + [P in keyof T]: KnockoutObservable|T[P]; +}; type KnockoutObservableType = { [P in keyof T]: KnockoutObservable; }; +type KnockoutObservableTypeRecursive = { + [P in keyof T]: KnockoutObservable|KnockoutObservableTypeRecursive; +}; +type KnockoutObservableTypeParameterRecursive = { + [P in keyof T]: KnockoutObservable|T[P]|KnockoutObservableTypeRecursive; +}; interface KnockoutStatic { utils: KnockoutUtils; @@ -443,11 +452,19 @@ interface KnockoutStatic { contextFor(node: any): any; isSubscribable(instance: any): instance is KnockoutSubscribable; toJSON(viewModel: any, replacer?: Function, space?: any): string; - toJS(viewModel: KnockoutObservableArray|KnockoutObservableType[]|KnockoutObservableArray>|T[]): T[]; - toJS(viewModel: KnockoutObservable|KnockoutObservableType|KnockoutObservable>|T): T; - isObservable(instance: KnockoutObservable|T): instance is KnockoutObservable; - isWriteableObservable(instance: KnockoutObservable|T): instance is KnockoutObservable; - isComputed(instance: KnockoutObservable|T): instance is KnockoutComputed; + + toJS(viewModel: KnockoutObservableArray|KnockoutObservableTypeParameterRecursive[]|KnockoutObservableArray>|T[]): T[]; + toJS(viewModel: KnockoutObservable|KnockoutObservableTypeParameterRecursive|KnockoutObservable>): T; + + isObservable(instance: any): instance is KnockoutObservable; + isObservable(instance: KnockoutObservable): instance is KnockoutObservable; + + isWriteableObservable(instance: any): instance is KnockoutObservable; + isWriteableObservable(instance: KnockoutObservable): instance is KnockoutObservable; + + isComputed(instance: any): instance is KnockoutComputed; + isComputed(instance: KnockoutObservable | T): instance is KnockoutComputed; + dataFor(node: any): any; removeNode(node: Node): void; cleanNode(node: Node): Node; From 61168b2479e69e6c4c14f2fba967fe0bc996ee23 Mon Sep 17 00:00:00 2001 From: Mathias Lorenzen Date: Mon, 26 Feb 2018 12:03:05 +0100 Subject: [PATCH 2/3] added new tests. --- types/knockout/index.d.ts | 9 ++++----- types/knockout/test/index.ts | 13 +++++++++++++ 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/types/knockout/index.d.ts b/types/knockout/index.d.ts index 54255c1c76..6d1dcbab59 100644 --- a/types/knockout/index.d.ts +++ b/types/knockout/index.d.ts @@ -416,10 +416,10 @@ type KnockoutObservableType = { [P in keyof T]: KnockoutObservable; }; type KnockoutObservableTypeRecursive = { - [P in keyof T]: KnockoutObservable|KnockoutObservableTypeRecursive; + [P in keyof T]: KnockoutObservable|T[P]>; }; -type KnockoutObservableTypeParameterRecursive = { - [P in keyof T]: KnockoutObservable|T[P]|KnockoutObservableTypeRecursive; +type KnockoutObservableSubTypeRecursive = { + [P in keyof T]: KnockoutObservable; }; interface KnockoutStatic { @@ -453,8 +453,7 @@ interface KnockoutStatic { isSubscribable(instance: any): instance is KnockoutSubscribable; toJSON(viewModel: any, replacer?: Function, space?: any): string; - toJS(viewModel: KnockoutObservableArray|KnockoutObservableTypeParameterRecursive[]|KnockoutObservableArray>|T[]): T[]; - toJS(viewModel: KnockoutObservable|KnockoutObservableTypeParameterRecursive|KnockoutObservable>): T; + toJS(viewModel: any): any; isObservable(instance: any): instance is KnockoutObservable; isObservable(instance: KnockoutObservable): instance is KnockoutObservable; diff --git a/types/knockout/test/index.ts b/types/knockout/test/index.ts index 36db7657ed..bc62702e0d 100644 --- a/types/knockout/test/index.ts +++ b/types/knockout/test/index.ts @@ -99,6 +99,19 @@ class GetterViewModel { public range: KnockoutObservable; } +function testToJs() { + var objKo = { + prop: ko.observable("prop"), + subKo: ko.observable({ + prop: ko.observable("prop") + }) + }; + + var objJs = ko.toJS(objKo); + objJs.prop; // $ExpectType any + objJs.subKo.prop; // $ExpectType any +} + function testGetter() { var model = new GetterViewModel(); From ac6f6b3e1f8f9abc2fcc8006d194f1b83e299206 Mon Sep 17 00:00:00 2001 From: Mathias Lorenzen Date: Mon, 26 Feb 2018 13:26:44 +0100 Subject: [PATCH 3/3] undo stuff. --- types/knockout/index.d.ts | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/types/knockout/index.d.ts b/types/knockout/index.d.ts index 6d1dcbab59..dc5cc833c1 100644 --- a/types/knockout/index.d.ts +++ b/types/knockout/index.d.ts @@ -409,19 +409,6 @@ interface KnockoutTasks { } ///////////////////////////////// -type KnockoutObservableTypeParameter = { - [P in keyof T]: KnockoutObservable|T[P]; -}; -type KnockoutObservableType = { - [P in keyof T]: KnockoutObservable; -}; -type KnockoutObservableTypeRecursive = { - [P in keyof T]: KnockoutObservable|T[P]>; -}; -type KnockoutObservableSubTypeRecursive = { - [P in keyof T]: KnockoutObservable; -}; - interface KnockoutStatic { utils: KnockoutUtils; memoization: KnockoutMemoization;