'Promise<any[]>' 类型的参数不可分配给 'readonly unknown[] 类型的参数

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

我有这样的代码-

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

我收到如下错误:

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)

如何解决?

该函数未返回承诺,

第一种方法不依赖于 studentsIds 数组。

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

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