Is there any way to convert promise into string, or maybe is there another way how to handle this result. Im getting an error "You cannot use an argument of type "Promise " for a parameter of type "string"."
const pokemonImgs: string[] = [];
interface PokemonImg {
img: string;
}
const getPokemonImg = async (id: number): Promise<PokemonImg> => {
const pokemonUrl = await fetch(`https://pokeapi.co/api/v2/pokemon/${id}`);
const pokemonImg = await pokemonUrl.json();
return pokemonImg.sprites.back_shiny;
};
const getPokemons = async () => {
try {
for (let i: number = 1; i <= 20; i++) {
pokemonImgs.push(getPokemonImg(i));
}
} catch (error) {
console.error(error);
}
};