Is there a way to convert a promise into a string, or is there another method for handling this result? I am encountering an error stating "You cannot use an argument of type 'Promise' for a parameter of type 'string'."
const pokemonImages: string[] = [];
interface PokemonImage {
img: string;
}
const getPokemonImage = async (id: number): Promise<PokemonImage> => {
const pokemonUrl = await fetch(`https://pokeapi.co/api/v2/pokemon/${id}`);
const pokemonImg = await pokemonUrl.json();
return pokemonImg.sprites.back_shiny;
};
const getMorePokemons = async () => {
try {
for (let i: number = 1; i <= 20; i++) {
pokemonImages.push(getPokemonImage(i));
}
} catch (error) {
console.error(error);
}
};