Skip to content
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

fix(toPromise): correct toPromise return type #5072

Merged
merged 2 commits into from
Jan 23, 2020

Conversation

jchv
Copy link
Contributor

@jchv jchv commented Oct 11, 2019

Description:
As described in #4196, the typing of toPromise does not match reality as it may return undefined in the case that no value is ever emitted. We have hit this bug in practice and believe it would be very useful to fix the actual typing.

(This does not implement the default argument as suggested in #4196 - while this seems like a reasonable addition, there are cases today where returning undefined is in fact desired, and it would be nice if the typing was correct for this case.)

Related issue (if exists):

(cc @sadarby)

@cartant
Copy link
Collaborator

cartant commented Oct 12, 2019

LGTM. Do you think you could add some dtslint tests? They would need to go into this file: https://github.com/ReactiveX/rxjs/blob/master/spec-dtslint/Observable-spec.ts

Also, whilst I agree with this change, there will need to be some discussion about it before it's merged. Although it fixes a problem, it is a breaking change. Whether or not it's okay for v7 or will have to wait until v8 will have to be determined.

@jchv
Copy link
Contributor Author

jchv commented Oct 14, 2019

Thanks, done. As a note, I had to run mkdir "$HOME/.dts" for dtslint to succeed, I am not sure why or if that's intended.

Also, whilst I agree with this change, there will need to be some discussion about it before it's merged. Although it fixes a problem, it is a breaking change. Whether or not it's okay for v7 or will have to wait until v8 will have to be determined.

Understood. There's definitely other approaches with varying pros/cons, but I think this one is pretty straightforward so I hope it or a compatible variant of it ends up working out.

Copy link
Collaborator

@cartant cartant left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@cartant
Copy link
Collaborator

cartant commented Oct 14, 2019

As a note, I had to run mkdir "$HOME/.dts" for dtslint to succeed, I am not sure why or if that's intended.

Yeah, that's happened to me, too. dtslint has been an ongoing source of frustration. It's a really useful tool and has helped improve the codebase, but some of the things it does are so annoying.

@benlesh
Copy link
Member

benlesh commented Oct 14, 2019

I think the real fix for toPromise is that it should reject if no value arrives with a known error, that's obviously a big breaking change. The point is that a Promise is a "promise" that a value will arrive. If it doesn't arrive, the promise is broken, IMO, and we should reject.

I know this has been discussed before, and I'm not saying we should break this for v7, but we should figure out if this is a change we want to make, given that it will make the change I'm suggesting even more breaking when it lands.

I think we should discuss this at the next meeting.

@benlesh benlesh added AGENDA ITEM Flagged for discussion at core team meetings blocked labels Oct 14, 2019
@jchv
Copy link
Contributor Author

jchv commented Oct 14, 2019

That also SGTM. I think that solution, though incompatible, basically serves the same purpose.

@benlesh benlesh removed AGENDA ITEM Flagged for discussion at core team meetings blocked labels Nov 20, 2019
@benlesh
Copy link
Member

benlesh commented Nov 20, 2019

Approved, but as a BREAKING CHANGE... (from Core Team meeting)

@benlesh benlesh merged commit b1c3573 into ReactiveX:master Jan 23, 2020
cartant added a commit to cartant/rxjs that referenced this pull request Jan 23, 2020
As toPromise can resolve to undefined via the change in ReactiveX#5072.
benlesh pushed a commit that referenced this pull request Jan 23, 2020
As toPromise can resolve to undefined via the change in #5072.
kwonoj pushed a commit to kwonoj/rxjs that referenced this pull request Feb 5, 2020
* fix(toPromise): correct toPromise return type

* fix(toPromise): add test for toPromise type

BREAKING CHANGE: toPromise return type now returns `T | undefined` in TypeScript, which is correct, but may break builds.
kwonoj pushed a commit to kwonoj/rxjs that referenced this pull request Feb 5, 2020
As toPromise can resolve to undefined via the change in ReactiveX#5072.
martinsik pushed a commit to martinsik/rxjs that referenced this pull request Feb 15, 2020
* fix(toPromise): correct toPromise return type

* fix(toPromise): add test for toPromise type

BREAKING CHANGE: toPromise return type now returns `T | undefined` in TypeScript, which is correct, but may break builds.
martinsik pushed a commit to martinsik/rxjs that referenced this pull request Feb 15, 2020
As toPromise can resolve to undefined via the change in ReactiveX#5072.
@lock lock bot locked as resolved and limited conversation to collaborators Feb 22, 2020
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.

3 participants