-
Notifications
You must be signed in to change notification settings - Fork 440
Consider making the value argument of promises optional. #1333
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
Comments
|
|
Ah sorry about that, is the TypeScript repository the correct place for this? |
It is, yes, but given the switch is pretty recent and release notes worthy (with some good arguments for why) I don't think the request is going to get too far. |
Yeah me neither, I'll mostly aim for point 3 in #1333 (comment) /** @type {Promise<void>} */
const promise = new Promise(r => fireCb(r));
await promise; is tedious to type. |
I've submitted microsoft/TypeScript#49390 |
I frequently pass in the promise callback argument into other functions that don't intend on providing any arguments in the callback function. For example:
admittedly this is a bit of a bad example, because setTimeout actually does provide an argument in its callback.
But consider the following:
playground link
Passing in
r
infireCallback
gives an error because the promise expectsr
to be called with a value, even though this is perfectly valid in JavaScript. The promise will simply resolve withundefined
.One way to work around this is by simply doing
new Promise<void>(r => fireCallback(r))
, but this isn't possible when working with JavaScript in strict mode. So the workaround ends up looking more like this:playground link
which is really verbose and tedious to write.
The
PromiseConstructor
is currently defined asmaking
value:
optional like so:solves this issue, but I'm not sure if it might break anything else.
The text was updated successfully, but these errors were encountered: