Skip to content

In new Promise, default T to void #23538

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

Closed
wants to merge 1 commit into from
Closed

In new Promise, default T to void #23538

wants to merge 1 commit into from

Conversation

ghost
Copy link

@ghost ghost commented Apr 19, 2018

Currently the following is a compile error:

new Promise(resolve => { resolve()) };

Because the constructor provides:

resolve: [T] extends [void] ? (value?: T | PromiseLike<T>) => void : (value: T | PromiseLike<T>) => void

Since there's no way to infer T, it is {} by default.
Before #22772, value was always optional and there was no problem. But now many DefinitelyTyped tests are failing because they rely on being able to call resolve() without providing an explicit type argument.
I think void makes a more sensible default than {}, which would fix the issue, but would technically be a breaking change because new Promise(resolve => { resolve({}); }) will now be broken.
(CC @falsandtru)

@ghost ghost requested a review from rbuckton April 19, 2018 15:36
@falsandtru
Copy link
Contributor

LGTM

@falsandtru
Copy link
Contributor

I found another problem. If Promise has an uninstantiated type parameter, we can't call resolve. So #22772 should be reverted.

<T>(a: T) => new Promise<T>(resolve => resolve(a)); // error

@ghost
Copy link
Author

ghost commented Apr 19, 2018

Looks like that's due to #7294 -- but if we're not fixing that soon we should probably revert #22772.

@falsandtru
Copy link
Contributor

Now working on #23545.

@ghost ghost closed this Apr 19, 2018
@ghost ghost deleted the promise-void branch April 19, 2018 19:34
@microsoft microsoft locked and limited conversation to collaborators Jul 30, 2018
This pull request was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant