I have a regular promise with a statically typed return type:
export const hasActiveSubscription = (whatEver: string): Promise<string> =>
new Promise((resolve, reject) => {
if (true){
resolve('imastring')
}
reject(new Error('nope'))
})
So far so good, but if I add a finally block, it changes the return type to unknown and fails to deliver that string type, e.g.
export const hasActiveSubscription = (whatEver: string): Promise<string> =>
new Promise((resolve, reject) => {
if (true){
resolve('imastring')
}
reject(new Error('nope'))
}).finally(console.info)
Type 'Promise' is not assignable to type 'Promise'.
Type 'unknown' is not assignable to type 'string'.
How can I retain the original return type while keeping the finally block?
If it helps, my actual code has a setTimeout (to be sure this function doesn't take too long to return) and I want to clear the timeout on finally, instead of clearing a timeout on 5 different locations.