Currently, I am working with TypeScript version 1.7.5 and the latest jQuery type definition available. However, when I attempt to make a call to $.getJSON(), it results in an error message stating "error TS2346: Supplied parameters do not match any signature of call target".
let url: string = api + '/orgs/' + orgname + '/repos?per_page=100';
$.getJSON(url, function(repos: Repo[]) {
...
});
The structure of 'Repo' is as follows:
export interface Repo {
name: string;
stargazers_count: number;
forks_count: number;
}
The type declaration for getJSON() stands as:
getJSON(url: string, success?: (data: any, textStatus: string, jqXHR: JQueryXHR) => any): JQueryXHR;
What could be causing this issue?
Update
Upon further inspection, I have discovered that the error actually originates from utilizing the error()
method after chaining a call to getJSON()
. Although this would normally work fine in regular jQuery, in TypeScript it triggers the error. Is there a way to handle errors returned by getJSON()
in TypeScript?
interface Repo {
name: string;
stargazers_count: number;
forks_count: number;
}
var url = "/echo/json/";
$.getJSON(url, (data: any, textStatus: string, jqXHR: JQueryXHR) => {
var repos: Repo[] = data;
//...
alert(JSON.stringify(repos));
})
.error(function() {
callback([]);
});