Skip to content
Advertisement

Tag: es6-promise

Why doesn’t TypeScript enforce async/await on promise?

I have the following code. performAsyncAction performs an async action and returns Promise<Response>. In someFunction , I was surprised that TypeScript doesn’t warn about not using await on a function that returns a promise. I found a relevant linting rule that may help promise-function-async Answer It is not an error, it is intended behaviour. The Promises existed long before async/await,

Why do both Promise’s then & catch callbacks get called?

I have the following code and when it’s executed, it returns both “rejected” and “success”: Could anyone explain why success is logged? Answer The then callback gets called because the catch callback is before it, not after. The rejection has already been handled by catch. If you change the the order (i.e. (promise.then(…).catch(…))), the then callback won’t be executed. MDN

Advertisement