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..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); + // 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); }); @@ -640,7 +641,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 +679,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"); 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();