Seem to be having some type issue by using async/await with .reduce()
I have to call one async function inside the reduce with proper types but I can’t figure out why Anyone pls help me
interface Person {
name: string;
age: number;
}
const persons: Person[] = [
{ name: 'John', age: 30 },
{ name: 'Alice', age: 45 },
];
function sleep(ms) {
return new Promise((resolve) => setTimeout(resolve, ms));
}
const ageByPerson: Person[] = persons.reduce<Person[]>(
async (result, person) => {
await sleep(4000);
return result.concat({
age: person.age,
name: person.name,
});
},
[]
);
console.log('age ', ageByPerson);
Without interface is working fine But when I am using with interface I can’t figure it out