Is it possible to force typescript to put methods on the instance not the prototype. I ask this because I frequently have \"this\" scope issues which having methods on the proto
It looks like this is a TypeScript/Knockout issue, as @Anzeo pointed out in his answer as well as your edit. I've gotten around the issue by putting my method declarations in the constructor but also using the var self = this;
convention pointed out in the "Managing 'this'" section on Knockout's Computed Observable documentation. You TS code could look like this:
class FooViewModel{
FooAlert: KnockoutObservableAny;
openFooAlertDialogueAdd: () => void;
constructor(){
var self = this;
self.FooAlert = ko.observable();
self.openFooAlertDialogueAdd = function(){
self.FooAlert('whatever your FooAlert observable takes');
};
}
}
No matter what scope change might occur, the JavaScript closure around self
keeps you from having to worry about this
changing. That should solve both your problems.