performanceeasyQuestion 7 of 70
User Dashboard Data Loader
Review the following TypeScript code and flag the issue.
TypeScript
1interface UserProfile {
2 id: string;
3 name: string;
4 email: string;
5 avatar: string;
6}
7
8async function fetchUser(id: string): Promise<UserProfile> {
9 const res = await fetch(`/api/users/${id}`);
10 return res.json();
11}
12
13async function loadDashboardUsers(userIds: string[]): Promise<UserProfile[]> {
14 const results: UserProfile[] = [];
15 for (const id of userIds) {
16 const data = await fetchUser(id);
17 results.push(data);
18 }
19 return results;
20}
21
22// Called on page load with ~100 user IDs
23app.get('/dashboard', async (req, res) => {
24 const userIds = req.query.ids as string[];
25 const users = await loadDashboardUsers(userIds);
26 res.json({ users });
27});