-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Unsafe declaration of resolve function in Promise constructor #22040
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Labels
Design Limitation
Constraints of the existing architecture prevent this from being fixed
Comments
We have already tried to address this, but unfortunately this resulted in either |
@ikokostya #22772 (comment) goes into a fair bit of detail on this |
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed. |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Uh oh!
There was an error while loading. Please reload this page.
TypeScript Version: [email protected]
Search Terms:
Promise, resolve
Code
tsconfig.json
:Expected behavior:
Compile error:
undefined
is not assignable tonumber
.Actual behavior:
No errors.
Playground Link: http://www.typescriptlang.org/play/index.html#src=function%20f()%3A%20Promise%3Cnumber%3E%20%7B%0A%20%20%20%20return%20new%20Promise((resolve)%20%3D%3E%20%7B%0A%20%20%20%20%20%20%20%20resolve()%3B%0A%20%20%20%20%7D)%3B%0A%7D
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#L33The provided example is correctly checked by
Flow
: https://flow.org/try/#0PQKgBAAgZgNg9gdzCYAoVUCuA7AxgFwEs5swoAKASgC4wAFAJzgFtCBnAUwB5tNmAjDgwB8YAN6owUsAw75MDUtg5JGLdh3LlZbODABuHSmAC8oidMsyOug5soBuSdIC+j1C9RAI trying to change declaration (i.e. make
value
parameter ofresolve
function is required) and the following code stop working:In
Flow
this code also works without error https://flow.org/try/#0PQKgBAAgZgNg9gdzCYAoVUCuA7AxgFwEs5swAjAQwCcAKASgC4wAFKuAW0IGcBTAHgBucQgBMAfGADeqMLLBUe+TFVLYeSVh248aNBVzgwBPOmAC8E6XOvyeBozroBuGXIC+z1G6AThe text was updated successfully, but these errors were encountered: