mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-07-04 09:10:09 +00:00
Merge pull request #26627 from Retsam/knockout-no-auto-null
Knockout: Remove hardcoded nulls for observables
This commit is contained in:
6
types/knockout/index.d.ts
vendored
6
types/knockout/index.d.ts
vendored
@@ -106,12 +106,14 @@ interface KnockoutObservableArray<T> extends KnockoutObservable<T[]>, KnockoutOb
|
||||
interface KnockoutObservableStatic {
|
||||
fn: KnockoutObservableFunctions<any>;
|
||||
|
||||
<T>(value?: T | null): KnockoutObservable<T>;
|
||||
<T = any>(): KnockoutObservable<T | undefined>
|
||||
<T = any>(value: null): KnockoutObservable<T | null>
|
||||
<T>(value: T): KnockoutObservable<T>;
|
||||
}
|
||||
|
||||
interface KnockoutObservable<T> extends KnockoutSubscribable<T>, KnockoutObservableFunctions<T> {
|
||||
(): T;
|
||||
(value: T | null): void;
|
||||
(value: T): void;
|
||||
|
||||
peek(): T;
|
||||
valueHasMutated?:{(): void;};
|
||||
|
||||
@@ -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 = "<div data-bind='template: { name: \"myTemplate\", \"if\": myProp }'></div>";
|
||||
|
||||
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 = "<div data-bind='template: { name: \"myTemplate\", \"if\": myProp, foreach: [$data, $data, $data] }'></div>";
|
||||
|
||||
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");
|
||||
|
||||
@@ -9,7 +9,7 @@ enum enumTest { male, female }
|
||||
*/
|
||||
function ObservableValidationTypes() {
|
||||
// any
|
||||
var t0 = ko.observable<any>()
|
||||
var t0 = ko.observable()
|
||||
.validate()
|
||||
.end();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user