We have encountered a scoping issue while using TypeScript classes with inheritance. It seems that TypeScript/JavaScript does not allow us to use 'super' within a promise structure or an enclosed function. The error message we are getting is:
TypeScript: 'super' Can Only Be Referenced in Members of Derived Classes or Object Literal Expressions
Is there a workaround for this problem? Below is the code snippet causing the issue:
export class VendorBill extends Transaction {
constructor() {
super();
}
save() {
let deferred = $.Deferred();
$.ajax({
type: "GET",
url: '/myrestapi',
success: function (data) {
deferred.resolve();
},
error: function (jqXHR: any, textStatus, errorThrown) {
deferred.reject()
}
})
$.when(deferred).always(function () {
super.save(); <----------- THIS IS CAUSING THE ERROR
})
}
}