In Typescript, can I define an interface function object with another interface as such below? I'm trying to define the object I'm going to use in my Ajax function.
But with this code I'm getting an error:
Error:(22, 1) TS2346: Supplied parameters do not match any signature of call target.
The error is set on instance.
interface IXHR {
Ajax(ajax: IAjax): string;
}
interface IAjax {
method: string;
url: string;
async: boolean;
callback?: (data: string) => void;
}
class XHR implements IXHR {
public Ajax(ajax: IAjax) {
return ajax.url;
}
constructor() {}
}
let instance = new XHR();
instance.Ajax('GET', 'URL', true);
Ajaxas defined inIXHRtakes one argument, while you tried to call it with your instance with 3 arguments