Skip to content

Commit

Permalink
fix(subscribable): make subscribe() signature match Observable (#4050)
Browse files Browse the repository at this point in the history
* fix(subscribable): make subscribe() signature match Observable

Fixes #3891

* test: cast string | number to string before concatenating

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.

* test: correct type for selector function

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.
  • Loading branch information
felixfbecker authored and benlesh committed Aug 27, 2018
1 parent 21fd0b4 commit 865d8d7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
6 changes: 3 additions & 3 deletions spec/operators/zipAll-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe('zipAll operator', () => {
of('a', 'b', 'c'),
of(1, 2, 3)
)
.pipe(zipAll((a, b) => a + b))
.pipe(zipAll((a, b) => String(a) + String(b)))
.subscribe((x) => {
expect(x).to.equal(expected[i++]);
}, null, done);
Expand Down Expand Up @@ -231,7 +231,7 @@ describe('zipAll operator', () => {
const b = [4, 5, 6];
const expected = '---x--#';

const selector = function (x: number, y: number) {
const selector = function (x: string, y: number) {
if (y === 5) {
throw new Error('too bad');
} else {
Expand Down Expand Up @@ -378,7 +378,7 @@ describe('zipAll operator', () => {
of('a', 'b', 'c'),
of(1, 2)
)
.pipe(zipAll((a, b) => a + b))
.pipe(zipAll((a, b) => String(a) + String(b)))
.subscribe((x) => {
expect(x).to.equal(expected[i++]);
}, null, done);
Expand Down
5 changes: 2 additions & 3 deletions src/internal/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,8 @@ export type SubscribableOrPromise<T> = Subscribable<T> | Subscribable<never> | P
/** OBSERVABLE INTERFACES */

export interface Subscribable<T> {
subscribe(observerOrNext?: PartialObserver<T> | ((value: T) => void),
error?: (error: any) => void,
complete?: () => void): Unsubscribable;
subscribe(observer?: PartialObserver<T>): Unsubscribable;
subscribe(next?: (value: T) => void, error?: (error: any) => void, complete?: () => void): Unsubscribable;
}

export type ObservableInput<T> = SubscribableOrPromise<T> | ArrayLike<T> | Iterable<T>;
Expand Down

0 comments on commit 865d8d7

Please sign in to comment.