I had this Promise that gave me TS-Lint errors in TypeScript.
error TS2322: Type 'boolean' is not assignable to type 'Promise<
void>'.
This was my function:
getBookVersions(): Promise<void> {
this.api.getBookVersions(this.book.id)
.then(async data => {
this.versions = data;
return true;
}).catch((error: Error | HttpErrorResponse) => {
if (error instanceof HttpErrorResponse) {
this.notificationService.showError(`Something went wrong.`);
}
else {
throw error;
}
return false;
});
}
To fix typing error you need to define the function as async, it is simple like that!
Makes sense actually, a promise is always async:
async getBookVersions(): Promise<void> {
...