From 500c118b36f52d24136a385649518fc212a95889 Mon Sep 17 00:00:00 2001 From: Retsam Date: Mon, 18 Jun 2018 00:56:53 -0400 Subject: [PATCH 1/3] Remove the hardcoded null in knockout observables --- types/knockout/index.d.ts | 6 ++++-- types/knockout/test/templatingBehaviors.ts | 6 +++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/types/knockout/index.d.ts b/types/knockout/index.d.ts index 1340e22d8f..fd30672d93 100644 --- a/types/knockout/index.d.ts +++ b/types/knockout/index.d.ts @@ -106,12 +106,14 @@ interface KnockoutObservableArray extends KnockoutObservable, KnockoutOb interface KnockoutObservableStatic { fn: KnockoutObservableFunctions; - (value?: T | null): KnockoutObservable; + (): KnockoutObservable + (value: null): KnockoutObservable + (value: T): KnockoutObservable; } interface KnockoutObservable extends KnockoutSubscribable, KnockoutObservableFunctions { (): T; - (value: T | null): void; + (value: T): void; peek(): T; valueHasMutated?:{(): void;}; diff --git a/types/knockout/test/templatingBehaviors.ts b/types/knockout/test/templatingBehaviors.ts index b69cb080f8..8d47b4551d 100644 --- a/types/knockout/test/templatingBehaviors.ts +++ b/types/knockout/test/templatingBehaviors.ts @@ -575,7 +575,7 @@ describe('Templating', function() { // Now set the observable to null and check it's treated like an empty array // (because how else should null be interpreted?) - myArray(null); + myArray(null as any); // DefinitelyTyped note: while KO accepts this, I wouldn't consider it a well-typed usage of the API expect(testNode.childNodes[0].childNodes.length).toEqual(0); }); @@ -640,7 +640,7 @@ describe('Templating', function() { ko.setTemplateEngine(new dummyTemplateEngine({ myTemplate: "Value: [js: myProp().childProp]" })); testNode.innerHTML = "
"; - var viewModel = { myProp: ko.observable({ childProp: 'abc' }) }; + var viewModel = { myProp: ko.observable<{childProp: string} | null>({ childProp: 'abc' }) }; ko.applyBindings(viewModel, testNode); // Initially there is a value @@ -678,7 +678,7 @@ describe('Templating', function() { ko.setTemplateEngine(new dummyTemplateEngine({ myTemplate: "Value: [js: myProp().childProp]" })); testNode.innerHTML = "
"; - var viewModel = { myProp: ko.observable({ childProp: 'abc' }) }; + var viewModel = { myProp: ko.observable<{childProp: string} | null>({ childProp: 'abc' }) }; ko.applyBindings(viewModel, testNode); expect(testNode.childNodes[0].childNodes[0].nodeValue).toEqual("Value: abc"); expect(testNode.childNodes[0].childNodes[1].nodeValue).toEqual("Value: abc"); From d46b8903fc9e2be6968112f3b237ca11bd1e22e2 Mon Sep 17 00:00:00 2001 From: Retsam Date: Fri, 22 Jun 2018 13:00:19 -0400 Subject: [PATCH 2/3] Use to indicate a type error --- types/knockout/test/templatingBehaviors.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/types/knockout/test/templatingBehaviors.ts b/types/knockout/test/templatingBehaviors.ts index 8d47b4551d..bf87b784da 100644 --- a/types/knockout/test/templatingBehaviors.ts +++ b/types/knockout/test/templatingBehaviors.ts @@ -575,7 +575,8 @@ describe('Templating', function() { // Now set the observable to null and check it's treated like an empty array // (because how else should null be interpreted?) - myArray(null as any); // DefinitelyTyped note: while KO accepts this, I wouldn't consider it a well-typed usage of the API + // DefinitelyTyped note: while KO accepts this, I wouldn't consider it a well-typed usage of the API + myArray(null); // $ExpectError expect(testNode.childNodes[0].childNodes.length).toEqual(0); }); From aacdcf725782c6d3d50c6f13afe0812ce2c4f6b9 Mon Sep 17 00:00:00 2001 From: Retsam Date: Fri, 22 Jun 2018 13:54:16 -0400 Subject: [PATCH 3/3] Fix a lint error in the valerie tests, due to changed default type param --- types/valerie/valerie-tests.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/valerie/valerie-tests.ts b/types/valerie/valerie-tests.ts index b4f6efcdc9..2121b20c64 100644 --- a/types/valerie/valerie-tests.ts +++ b/types/valerie/valerie-tests.ts @@ -9,7 +9,7 @@ enum enumTest { male, female } */ function ObservableValidationTypes() { // any - var t0 = ko.observable() + var t0 = ko.observable() .validate() .end();