Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

219
Visualizações
El argumento de tipo 'Promise<any[]>' no se puede asignar al parámetro de tipo 'readonly unknown[]

Tengo un código como este-

 async function fetchData() { xlData.map(async (student, id) => { const studentExist = await User.findOne({ email: student.email, }); if (studentExist) { let includesStudent = await Class.findOne({ student: { $in: [studentExist._id] }, }); if (!includesStudent) { studentsIds.push(studentExist._id); } } }); return studentsIds; } const finalData: any[] = await Promise.all(fetchData()); console.log("final data", finalData);

Estoy recibiendo un error de la siguiente manera:

 No overload matches this call. Overload 1 of 2, '(values: readonly unknown[] | []): Promise<unknown[] | []>', gave the following error. Argument of type 'Promise<any[]>' is not assignable to parameter of type 'readonly unknown[] | []'. Type 'Promise<any[]>' is not assignable to type '[]'. Overload 2 of 2, '(values: Iterable<any>): Promise<any[]>', gave the following error. Argument of type 'Promise<any[]>' is not assignable to parameter of type 'Iterable<any>'. Property '[Symbol.iterator]' is missing in type 'Promise<any[]>' but required in type 'Iterable<any>'.ts(2769)

¿Cómo resolver esto?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

La función no está devolviendo una promesa,

El primer enfoque no depende de la matriz studentIds.

 const fetchData = () => { const promises = xlData.map(async (student, id) => { const studentExist = await User.findOne({ email: student.email, }); if (studentExist) { let includesStudent = await Class.findOne({ student: { $in: [studentExist._id] }, }); if (!includesStudent) { return studentExist._id; } } }); return promises; }; const result: any[] = await Promise.all(fetchData()); //remove undefined const students = result.filter((student) => Boolean(student)); console.log("final data", students);

O

 async function fetchData() { await Promise.all( xlData.map(async (student, id) => { const studentExist = await User.findOne({ email: student.email, }); if (studentExist) { let includesStudent = await Class.findOne({ student: { $in: [studentExist._id] }, }); if (!includesStudent) { studentsIds.push(studentExist._id); } } }) ); return studentsIds; }
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda