I'm writing a little MVC app in Typescript but i have prolem. If i extend my BaseController and override the ajaxMethod what needs diferent parameters my transpiler makes an error. hope someone can help me.
here's my code:
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();
}
}
at the moment i don't know where i am false on extending my classes. constructor can be overwritten without any problems, and the listeners too. why not the ajaxMethod?
Page_1_Controllerclass, you are not overwriting the base constructor but writing a new one.