Description
TypeScript Version: typescript@2.8.0-dev.20180217
Search Terms:
Promise, resolve
Code
function f(): Promise<number> {
return new Promise((resolve) => {
resolve();
});
}
tsconfig.json
:
{
"compilerOptions": {
"module": "commonjs",
"moduleResolution": "node",
"target": "es2017",
"lib": ["es2017"],
"alwaysStrict": true,
"noEmitOnError": true,
"pretty": true,
"strict": true
}
}
Expected behavior:
Compile error: undefined
is not assignable to number
.
Actual behavior:
No errors.
Looks like this happens, because resolve()
function in Promise executor takes optional argument https://github.com/Microsoft/TypeScript/blob/b3edc8f9f4d9cf4203c4c4493e4f0f3dc96c845d/lib/lib.es2015.promise.d.ts#L33
The provided example is correctly checked by Flow
: https://flow.org/try/#0PQKgBAAgZgNg9gdzCYAoVUCuA7AxgFwEs5swoAKASgC4wAFAJzgFtCBnAUwB5tNmAjDgwB8YAN6owUsAw75MDUtg5JGLdh3LlZbODABuHSmAC8oidMsyOug5soBuSdIC+j1C9RA
I trying to change declaration (i.e. make value
parameter of resolve
function is required) and the following code stop working:
function bar(): Promise<void> {
return new Promise((resolve) => {
resolve(); // Expected 1 arguments, but got 0.
});
}
In Flow
this code also works without error https://flow.org/try/#0PQKgBAAgZgNg9gdzCYAoVUCuA7AxgFwEs5swAjAQwCcAKASgC4wAFKuAW0IGcBTAHgBucQgBMAfGADeqMLLBUe+TFVLYeSVh248aNBVzgwBPOmAC8E6XOvyeBozroBuGXIC+z1G6A
Activity
rbuckton commentedon May 9, 2018
We have already tried to address this, but unfortunately this resulted in either
Promise
no longer being extensible or other breaks.ikokostya commentedon May 15, 2018
@mhegazy @rbuckton Can you provide more detailed description why this is
Design Limitation
? From my point of view need ad-hoc solution to allow callresolve()
withoutundefined
argument forPromise<void>
type.RyanCavanaugh commentedon May 15, 2018
@ikokostya #22772 (comment) goes into a fair bit of detail on this
typescript-bot commentedon May 30, 2018
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.