Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

203
Vistas
Argument of type 'Promise<any[]>' is not assignable to parameter of type 'readonly unknown[]

I have a code like this-

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);

I am getting an error as follows:

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)

How to solve this?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The function is not returning a promise,

The first approach it's not dependent on the studentsIds array.

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);

OR

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda