Wie man async/await mit Array.map in TypeScript verwendet
Hallo zusammen! Ich bin ein Anfänger in TypeScript und habe ein Problem mit der Verwendung von async/await zusammen mit der Methode `Array.map`. Ich schreibe eine Funktion, die ein Array von URLs verarbeiten, Daten von jeder URL laden und ein Array von Ergebnissen zurückgeben soll.
Hier ist mein TypeScript-Code:
```typescript
interface Post {
id: number;
title: string;
}
async function fetchPost(id: number): Promise {
const response = await fetch(`https://jsonplaceholder.typicode.com/posts/${id}`);
return response.json();
}
async function fetchAllPosts(ids: number[]): Promise {
return ids.map(async (id) => {
const post = await fetchPost(id);
return post;
});
}
const result = await fetchAllPosts([1, 2, 3]);
console.log(result); // Was werde ich bekommen?
```
Wenn ich