Код: Выделить всё
class ItemsService {
async getItems(fetchAmounts = false) {
if (fetchAmounts === true) {
const {
items = [],
} = await this.getAmounts(userId);
} else {
const {
items = [],
} = await this.getCounts(userId);
}
console.log(`items: ${JSON.stringify(items)}`);
}
}
< /code>
getAmounts и getCounts являются асинхронными. Console.log не удается, потому что элементы не определены после оператора if/else, несмотря на ожидание. Кроме того, запуск Eslint в коде результаты в: < /p>
5:13 error 'items' is assigned a value but never used no-unused-vars
9:13 error 'items' is assigned a value but never used no-unused-vars
13:13 error 'items' is not defined no-undef
Код: Выделить всё
class ItemsService {
async getItems(fetchAmounts = false) {
const {
items = [],
} = await this.getAmounts(userId);
}
console.log(`items: ${JSON.stringify(items)}`);
}
Подробнее здесь: https://stackoverflow.com/questions/794 ... else-block