-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Improve Promise type definition #10448
Conversation
👍 |
* Creates a new Promise with the same internal state of this Promise. | ||
* @returns A Promise. | ||
*/ | ||
then(): Promise<T>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought overloads should be arranged longest-to-shortest to make sure that the most restrictive overloads matches first. Why change that here?
The change in 9d4219a fixes an existing issue with assignability between |
@@ -8,42 +8,45 @@ interface Promise<T> { | |||
* @param onrejected The callback to execute when the Promise is rejected. | |||
* @returns A Promise for the completion of which ever callback is executed. | |||
*/ | |||
then<TResult1, TResult2>(onfulfilled: (value: T) => TResult1 | PromiseLike<TResult1>, onrejected: (reason: any) => TResult2 | PromiseLike<TResult2>): Promise<TResult1 | TResult2>; | |||
then(onfulfilled?: ((value: T) => T | PromiseLike<T>) | undefined | null, onrejected?: ((reason: any) => T | PromiseLike<T>) | undefined | null): Promise<T>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This overload is meant to replace then(): Promise<T>
as that overload was one of the causes of #10524.
👍 |
@mhegazy, do you want to take this change for release-2.0 as well? |
no. jsut 2.1 please. |
This change modifies the overloads for
then
andcatch
ofPromise<T>
, and the overloads forthen
ofPromiseLike<T>
to provide better type inference.Fixes #4903