
TypeScript 4 Design Patterns and Best Practices
By :

Let's start with the most popular Reactive programming structure, which is the Promise. A Promise is a container for single future computations. A future computation is a result of a function call that will finish in future time and not immediately. The way that Promises work is by creating a container that can either resolve to a value in the future or reject with a message.
Simply speaking, a Promise is when you call a function and instead of returning an actual value, it returns an object that promises you that a value will be returned at some point. The creator of the Promise object will have to get this value by checking on the outcome of this computation at a later time, be it successful by resolving, or unsuccessful by rejecting.
Let's see a typical example of how you will use Promises in the real world:
Promises.ts
const fetch = require("node-fetch"); const pullFromApi = new Promise(async (resolve, reject)...