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.