Today I learned

No floating promises

Edit this Post Opens in new tab

If you have worked with Promises in JavaScript, you know that Promises returned by functions must be handled appropriatly.

Unhandled Promises can cause unexpected behavior. For example they can resolve when you don't expext it.

So the best way to deal with Promises is to return them from functions that start them and then handle them.

To enforce this behaviour and prevent unhandled promises, you can use this tslint rule: no-floating-promises Opens in new tab

I find it really helpful and it can reveal a lot of bad code and potential non-determistic behaviour.

I hope you enjoyed this post and learned something new. If you have any questions, feel free to reach out to me on Twitter Opens in new tab or via Email Opens in new tab.

If you want to support me, you can buy me a coffee. I would be very happy about it!

☕️ Buy me a coffee ☕️

I wish you a wonderful day! Marco