Open Sc0tTyXL opened 3 years ago
What TypeScript version are you using? It works fine with 4.3.5:
https://codesandbox.io/s/typescript-playground-export-forked-ej4hy?file=/index.ts
We were running v4.3.2 and updated to v4.3.5 but no joy.
hi @Sc0tTyXL
{
"compilerOptions": {
"target": "es5",
"lib": ["dom", "es5", "es2015.promise", "es2015.iterable"]
}
}
even you are using es2015.promise and es2015.iterable but its runtime compiler wont use promises without polyfil. use polyfil to execute promise base execution at run time in es2015
npm i core-js
//AND
import 'core-js/es6/promise'
use promise like we do in es6 and passing nothing in resolve would be interpreted as **void**
const myPromise: Promise<void> = new Promise<void>((resolve, reject) => {
setTimeout(() => {
console.log("Async operation completed");
resolve(); // No value returned --void--
}, 1000);
});
Configuration Check
My compilation target is
es5
and my lib isdom
,es5
,es2015.promise
andes2015.iterable
.Missing / Incorrect Definition
The value for the resolve callback in the
Promise
constructor is required:new <T>(executor: (resolve: (value: T | PromiseLike<T>) => void, reject: (reason?: any) => void) => void): Promise<T>;
Sample Code
Using
void
as the generic (return) type for aPromise
results in an error:Workaround
The current workaround is to return
undefined
:But
undefined
is not the same asvoid
: https://www.typescriptlang.org/docs/handbook/2/functions.html#void