I have just started switching from javascript to typescipt. I am using knockout for obvious advantages it has to offer.
I need to define a knockout computed observable which is dependent on the value of another knockout observable. Return true if the observable is valid else return false.
This is how I have structured the code -
class anyClass {
private address: KnockoutObservable<any> = ko.observable().extend({ required : true});
private canPrintAddresses : KnockoutComputed<boolean> = ko.computed((): any => {
if (this.address.isValid()) {
return true;
}
else
return false;
});
}
I even tried to define the computed inside the constructor, but the compiler is indifferent. I don't know where I am going wrong, but the compiler keeps on giving error - "property 'isValid' does not exist on type 'KnockoutObservable'".
Since, I am also using durandal, so I tried to define it inside the activate event handler, but then this requires the evaluation to be done on the activation of the page when there is no value attached to the observable.
Please help.