I am currently working on a Typescript MVC app and encountering an issue. When I try to extend my BaseController and override the ajaxMethod with different parameters, my transpiler throws an error. Any help would be appreciated.
Below is the code snippet:
interface i_Controller {
ajaxMethod;
ajaxSuccessListener;
ajaxErrorListener;
}
class BaseController implements i_Controller {
protected baseProperty: boolean;
constructor() {
this.baseProperty = true;
}
public ajaxMethod() {
$.when(
$.ajax({})
).then(
this.ajaxSuccessListener,
this.ajaxErrorListener
)
}
public ajaxSuccessListener(data, status, jqXHR) {
console.log('ajax success');
console.log(data);
};
public ajaxErrorListener(jqXHR, status, error) {
console.error('ajax error');
console.error(status);
};
}
class Page_1_Controller extends BaseController {
private localProperty: number;
constructor(input) {
super();
this.localProperty = input;
}
public ajaxMethod(someProperty) {
/*
/* Error:(39, 7) TS2415:Class 'Page_1_Controller' incorrectly
/* extends base class 'BaseController'.
/* Types of property 'ajaxMethod' are incompatible.
/* Type '(someProperty: any) => void' is not assignable to
/* type '() => void'.
*/
$.when(
$.ajax({
data: {properties: someProperty}
}),
$.ajax({})
).then(
this.ajaxSuccessListener,
this.ajaxErrorListener
)
}
public ajaxSuccessListener(responseAjaxRequest_1, responseAjaxRequest_2) {
console.log('ajax success');
let data_1 = responseAjaxRequest_1[0];
let data_2 = responseAjaxRequest_2[0];
console.log(data_1);
console.log(data_2);
}
}
class MyApp {
private controller: i_Controller;
constructor() {
this.controller = new Page_1_Controller();
/*
/* Error:(72, 27) TS2346:Supplied parameters do not match any
/* signature of call target.
*/
this.controller.ajaxMethod();
}
}
Currently unsure why extending my classes is causing issues. Overwriting constructors and listeners works fine, so why not the ajaxMethod?