Categories
TypeScript Answers

How to use TypeScript with native ES6 Promises?

Spread the love

Sometimes, we want to use TypeScript with native ES6 Promises.

In this article, we’ll look at how to use TypeScript with native ES6 Promises.

How to use TypeScript with native ES6 Promises?

To use TypeScript with native ES6 Promises, we can use the Promise constructor.

For instance, we write

const p = new Promise<string>((resolve, reject) => {
  resolve("a string");
});

to create a new Promise instance.

We specify that the promise resolves to a string value with <string>.

And we call resolve with a string to make the promise resolve to a string value.

Conclusion

To use TypeScript with native ES6 Promises, we can use the Promise constructor.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *