Property 'includes' does not exist on type 'number[]'. Unable to resolve error even after changing lib in tsconfig.json [duplicate]
I'm using a function to fetch data from an API. Afterwards I'm trying to push part of that data (some id's) into an array, if that id is not already included. I wanted to use the .includes() method to check for this but I keep getting "error TS2550: Property 'includes' does not exist on type 'number[]'."
This is the code below:
// Get data from API
const getFixturesData = () => {
// Here I am fetching the data
let domain: string = "https://v3.football.api-sports.io/fixtures?";
let league: string = (document.getElementById("league")! as HTMLInputElement).value;
let date: string = (document.getElementById("date-picker")! as HTMLInputElement).value;
(async (url: string) => {
const response: Response = await fetch(url, {
"method": "GET",
"headers": {
"x-rapidapi-host": "v3.football.api-sports.io",
"x-rapidapi-key": "personal API key"
}
});
return response.json();
})(`${domain}date=${date}&status=FT`).then(value => {
// Here I am parsing the data
let fixtures: any[] = [];
let competitions: number[] = [];
if (league == "") {
fixtures = value.response;
for (let event in fixtures) {
competitions.push(parseInt(fixtures[event].league.id));
}
} else {
let allFixtures: any[] = value.response;
for (let event in allFixtures) {
if (allFixtures[event].league.id == league) {
fixtures.push(allFixtures[event]);
// Here is where I am trying to use .includes()
if (!(competitions.includes(parseInt(allFixtures[event].league.id)))) {
competitions.push(parseInt(allFixtures[event].league.id));
}
}
}
}
}
Other solutions that I found online point to changing the lib in the tsconfig.json file. I tried multiple options but none of them worked. I get the same error. Here is the current configuration of the file. I only pasted the rows which are not commented out.
I'm using TypeScript 4.8.3 . I'm a beginner in TypeScript so pardon any gross mistakes that you may observe.
{
"compilerOptions":{
"target":"ES2015",
"lib":[
"DOM",
"ES2022"
],
"module":"commonjs",
"esModuleInterop":true,
"forceConsistentCasingInFileNames":true,
"strict":true
}
}
Thank you for your time!
Via Active questions tagged javascript - Stack Overflow https://ift.tt/6vIHQ4Z
Comments
Post a Comment