Encountering an error from TSLint, I am working to comprehend why it is raising concerns.
In my code, there is a function that calls another method which returns a promise. However, the initial function does not return the promise; instead, it waits for completion and updates an internal state.
To simplify the scenario, here is a snippet using Q()
to simulate a promise-invoking call:
export function DoSomethingAsync(): void {
Q().then(r => {
console.log('test');
}).catch(err => {
log.error("wow");
}).finally(() => {
log.info("at finally")
});
}
Upon running tslint
, the following error surfaces:
ERROR: C:/dev/local_cache_service.ts[31, 5]: Promises must be handled appropriately
Eliminating the finally
block allows TSLint to complete without errors:
export function DoSomethingAsync(): void {
Q().then(r => {
console.log('test');
}).catch(err => {
log.error("wow");
});
}
Interestingly, this issue does not occur when implementing the same function in a seed TypeScript project...