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(subscribable): make subscribe() signature match Observable #4050

Merged
merged 3 commits into from
Aug 27, 2018

Conversation

felixfbecker
Copy link
Contributor

@felixfbecker felixfbecker commented Aug 23, 2018

Description:
The signature of Subscribable.subscribe() did not match that of Observable.subscribe(), which made the two types not compatible if T=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

@ci-reporter
Copy link

ci-reporter bot commented Aug 23, 2018

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:

npm test
> @reactivex/rxjs@6.2.2 test /home/travis/build/ReactiveX/rxjs
> cross-env TS_NODE_PROJECT=spec/tsconfig.json mocha --opts spec/support/default.opts "spec/**/*-spec.ts"


/home/travis/build/ReactiveX/rxjs/node_modules/ts-node/src/index.ts:250
    return new TSError(diagnosticText, diagnosticCodes)
           ^
TSError: ⨯ Unable to compile TypeScript:
spec/operators/zipAll-spec.ts(42,28): error TS2365: Operator '+' cannot be applied to types 'string | number' and 'string | number'.
spec/operators/zipAll-spec.ts(240,38): error TS2345: Argument of type 'OperatorFunction<ObservableInput<number>, number>' is not assignable to parameter of type 'OperatorFunction<number[] | HotObservable<string>, number>'.
  Type 'number[] | HotObservable<string>' is not assignable to type 'ObservableInput<number>'.
    Type 'HotObservable<string>' is not assignable to type 'ObservableInput<number>'.
      Type 'HotObservable<string>' is not assignable to type 'Iterable<number>'.
        Property '[Symbol.iterator]' is missing in type 'HotObservable<string>'.
spec/operators/zipAll-spec.ts(381,28): error TS2365: Operator '+' cannot be applied to types 'string | number' and 'string | number'.

    at createTSError (/home/travis/build/ReactiveX/rxjs/node_modules/ts-node/src/index.ts:250:12)
    at getOutput (/home/travis/build/ReactiveX/rxjs/node_modules/ts-node/src/index.ts:358:40)
    at Object.compile (/home/travis/build/ReactiveX/rxjs/node_modules/ts-node/src/index.ts:545:11)
    at Module.m._compile (/home/travis/build/ReactiveX/rxjs/node_modules/ts-node/src/index.ts:430:43)
    at Module._extensions..js (module.js:663:10)
    at Object.require.extensions.(anonymous function) [as .ts] (/home/travis/build/ReactiveX/rxjs/node_modules/ts-node/src/index.ts:433:12)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
    at Module.require (module.js:596:17)
    at require (internal/module.js:11:18)
    at /home/travis/build/ReactiveX/rxjs/node_modules/mocha/lib/mocha.js:231:27
    at Array.forEach (<anonymous>)
    at Mocha.loadFiles (/home/travis/build/ReactiveX/rxjs/node_modules/mocha/lib/mocha.js:228:14)
    at Mocha.run (/home/travis/build/ReactiveX/rxjs/node_modules/mocha/lib/mocha.js:536:10)
    at Object.<anonymous> (/home/travis/build/ReactiveX/rxjs/node_modules/mocha/bin/_mocha:582:18)
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
    at Function.Module.runMain (module.js:693:10)
    at startup (bootstrap_node.js:191:16)
    at bootstrap_node.js:612:3

I'm sure you can fix it! If you need help, don't hesitate to ask a maintainer of the project!


This comment was automagically generated by ci-reporter. If you see a problem, open an issue here.

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.
@felixfbecker
Copy link
Contributor Author

I wish rxjs could just get rid of all the unneeded project functions

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.2%) to 96.783% when pulling 2706b1a on felixfbecker:fix-subscribable into 9ea0ec9 on ReactiveX:master.

@benlesh benlesh merged commit 865d8d7 into ReactiveX:master Aug 27, 2018
@felixfbecker felixfbecker deleted the fix-subscribable branch August 27, 2018 18:12
@lock lock bot locked as resolved and limited conversation to collaborators Sep 26, 2018
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.

Observable<never> is not assignable to Subscribable<T>
4 participants