Creating Promises in TypeScript.
Without Promise class.
Works even if Promise is null.
Promise = null;
globalThis.Promise = null;
const { promise, resolve, reject } = await createNativePromise();Contains as unknown as.
Promise = null;
globalThis.Promise = null;
const { promise, resolve, reject } = createNativePromiseSync();No as unknown as.
Note that the callback will always be called asynchronously.
createPromiseAsync((promise, resolve, reject) => {
});Contains as unknown as.
JS dist can't pass //@ts-check.
Note that the callback will always be called synchronously.
createPromiseSync((promise, resolve, reject) => {
});No as unknown as.
Nested promise.
createPromisePromised().then(({ promise, resolve, reject }) => {
});The classic way using as unknown as.
JS dist can't pass //@ts-check.
var { promise, resolve, reject } = createPromise();