Below are my typescript functions. When I edit in vscode, the second function does not show any error message. However, upon compilation, an error is displayed for the second function:
error TS2322: Type 'Promise<void>' is not assignable to type 'Promise<Item[]>'.
Type 'void' is not assignable to type 'Item[]'.
The error disappears when I remove .catch(...)
. Can someone please assist me?
// Function to retrieve a single item.
// Q is https://github.com/kriskowal/q
function getItem(id: number): Q.Promise<Item> {
const deferred = Q.defer<Item>();
// Asynchronous process.
return deferred.promise;
}
// Function to retrieve a batch of items.
function getItems(ids: number[]): Q.Promise<Item[]> {
return Q.all(ids.map(id => {
return getSingleItem(id);
})).then(results => {
let items = [];
results.forEach(result => {
items = items.concat(result);
});
return items;
}).catch(error => {
throw error;
});
}