I have this two errors from eslint:
error Promise returned in function argument where a void return was expected error Promise executor functions should not be async
They comes from this code:
const promiseFeature = new Promise(async (resolve) => {
let objectProfile = await this.userFeaturesRepository.findById(id);
objectProfile = await this.userFeaturesRepository.getProfileObj(myUserFeatures);
await this.userFeaturesRepository.updateById(id, objectProfile);
resolve()
})
const promiseIAM = new Promise(async (resolve) => {
let objectIAM = await this.userIAMRepository.findById(id);
objectIAM = await this.userIAMRepository.getIAMObj(myUserFeatures);
objectIAM.email = objectIAM.email.toLowerCase();
await this.userIAMRepository.updateById(id, objectIAM);
resolve()
})
await Promise.all([promiseFeature, promiseIAM]);
The code works, but I really don´t know who to solve the eslint problem.
Thanks, In advance.
Try this:
const promiseFeature = new Promise((resolve) => {
(async() => {
let objectProfile = await this.userFeaturesRepository.findById(id);
objectProfile = await this.userFeaturesRepository.getProfileObj(myUserFeatures);
await this.userFeaturesRepository.updateById(id, objectProfile);
resolve()
})();
})
const promiseIAM = new Promise((resolve) => {
(async() => {
let objectIAM = await this.userIAMRepository.findById(id);
objectIAM = await this.userIAMRepository.getIAMObj(myUserFeatures);
objectIAM.email = objectIAM.email.toLowerCase();
await this.userIAMRepository.updateById(id, objectIAM);
resolve()
})();
})
await Promise.all([promiseFeature, promiseIAM]);
I guess what's happening here is ESLint is expecting the callback function in your promises to return void
but they're returning promises since they are async
.
See the "Return Value" section on this page from MDN .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.