-
Notifications
You must be signed in to change notification settings - Fork 3k
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(subscribable): make subscribe() signature match Observable #4050
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The build is failing✨ Good work on this PR so far! ✨ Unfortunately, the Travis CI build is failing as of 2ecf10b. Here's the output:
|
T of this Observable is string | number, so TypeScript does not allow using +. The desired behaviour for this function is to concatenate the string values, so cast to strings. On master, these were incorrectly inferred as never, which is why this error was not surfaced.
The hot() function will create an Observable that emits strings from marble diagrams (even if the strings contain numbers). So the type of x should be string, not number.
I wish rxjs could just get rid of all the unneeded |
cartant
approved these changes
Aug 24, 2018
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description:
The signature of
Subscribable.subscribe()
did not match that ofObservable.subscribe()
, which made the two types not compatible ifT=never
(see linked issue).It also was wrong, because it allowed passing both an Observer and functions at the same time.
This makes it match the signature of
Observable.subscribe()
exactly, which solves the type error in the issue.It is not breaking (unless you passed both observer and functions, which is extremely unlikely and did not work at runtime anyway as
SafeSubscriber
checks if the first argument is a function and if yes, discards the other arguments, so this would only highlight a bug).The alternative discussed in the issue was removing the 3-arg overload, but the discussion in the spec does not seem resolved yet, it is not clear that the interface is supposed to represent the spec, it would be a breaking change and require way more changes in rxjs (it did not compile when I tried).
Related issue (if exists):
Fixes #3891
cc @cartant