For the golfers out there, we can combine these two lines into one:
const items = await getCollection();
return items.sort();
This doesn’t work because sort() is being called on the promise returned by
getCollection():
return await getCollection().sort(); // `sort()` runs on the Promise
Instead, wrap the await expression in parentheses so sort() is called on the
resolved value:
return (await getCollection()).sort(); // `sort()` runs on the resolved array
- Promise documentation - MDN