• Typescript Daily
  • Posts
  • trojan.exe can be your domain if you wish to. Fed up with nesting your implementations inside Promise? this one is for you!

trojan.exe can be your domain if you wish to. Fed up with nesting your implementations inside Promise? this one is for you!

This fools day edition is no joke :)

Welcome to our 149th edition!

🔥 Top Stories

  1. Google registry launches top-level .exe domain. (TLD) Trust me. I’m not April fooling you 😆 

  2. Promise.withResolvers() - From March 2024, it works across various browsers.

  3. Use Node’s default util for styleText. You can drop all the chalk and other style npm packages just to style your console logs.

🌟 Spotlight

Let’s talk about the brand new Promise.withResolvers() 🎉 

I can assure you this one is going to be used forever. This falls into the category of Promise.then vs async/await. Async/await has been a clear winner in terms of readability, maintainability, and error handling.

The Promise.withResolvers() static method returns an object containing a new Promise object and two functions to resolve or reject it, corresponding to the two parameters passed to the executor of the Promise() constructor.

Ok, this is how it looks.

Promise.withResolvers

It returns a promise instance, resolve, and reject methods. This can be passed on elsewhere accordingly.

Alright, now help me understand what’s the problem with the existing Promise implementation and how is this helpful.

Sure.

Example:

Let’s say you want to implement a delay function using promises. The invoking code will wait until the promise gets executed creating a virtual delay of sorts.

Old Promise implementation

With Promise.withResolvers()

With the ability to have the resolve method outside of the Promise’s scope, we no longer need to move our implementation logic inside Promise function just to use resolve or reject. This makes the code easier to read and scalable to maintain and extend.

Checkout this twitter post by Wes Bos for more examples and use cases. Read through this MDN blog for further details, browser support, …

jQuery

3p cookies

😂 Fun memes

Damn, you regex!

💬 What do you think about this?

Just hit reply and let us know your thoughts!

📢 Calling for contributions

This newsletter thrives on community contributions. Your expertise, insights, and experiences matter to us! We're open to featuring articles written by our readers.

If you have a valuable perspective, a TypeScript tip, or a frontend engineering story to share, we welcome your submissions!

Just hit reply, and we will connect!

🌻 Your support matters! 🌻

Researching and writing high-quality articles demands considerable time and effort. As this newsletter is offered for free and managed alongside a full-time commitment, your support can help sustain its quality and growth.

If you enjoy the content and find it valuable, please consider supporting my efforts by visiting this link. Every contribution helps in maintaining and enhancing the newsletter's content and reach.

Thank you for being part of this journey!

Reply

or to participate.