From f7e4c02444adc98732c2040201337b40e72dfabf Mon Sep 17 00:00:00 2001 From: David Driscoll Date: Tue, 20 Feb 2018 01:43:16 -0500 Subject: [PATCH] feat(typings): updated typings for combineAll, mergeAll, concatAll, switch, exhaust, zipAll (#3321) this adds support for nested observables using some of the newest features of the TypeScript compiler. Also updated tests in related areas --- spec/observables/combineLatest-spec.ts | 72 ++--- spec/observables/concat-spec.ts | 10 +- spec/observables/merge-spec.ts | 2 +- spec/operators/combineAll-spec.ts | 177 ++++++++++--- spec/operators/combineLatest-spec.ts | 64 ++--- spec/operators/concat-spec.ts | 25 +- spec/operators/concatAll-spec.ts | 115 +++++--- spec/operators/concatMap-spec.ts | 192 +++++++------- spec/operators/concatMapTo-spec.ts | 50 ++-- spec/operators/exhaust-spec.ts | 115 +++++--- spec/operators/exhaustMap-spec.ts | 68 ++--- spec/operators/expand-spec.ts | 55 ++-- spec/operators/merge-spec.ts | 20 +- spec/operators/mergeAll-spec.ts | 98 +++++-- spec/operators/mergeMap-spec.ts | 152 +++++------ spec/operators/mergeMapTo-spec.ts | 62 ++--- spec/operators/mergeScan-spec.ts | 51 ++-- spec/operators/switch-spec.ts | 104 ++++++-- spec/operators/switchMap-spec.ts | 60 ++--- spec/operators/switchMapTo-spec.ts | 10 +- spec/operators/zip-spec.ts | 27 +- spec/operators/zipAll-spec.ts | 261 +++++++++++++------ src/internal/observable/concat.ts | 2 +- src/internal/observable/merge.ts | 2 +- src/internal/operators/combineAll.ts | 6 +- src/internal/operators/concatAll.ts | 10 +- src/internal/operators/exhaust.ts | 9 +- src/internal/operators/expand.ts | 14 +- src/internal/operators/mergeAll.ts | 9 +- src/internal/operators/switchAll.ts | 7 +- src/internal/operators/zipAll.ts | 7 +- src/internal/patching/operator/combineAll.ts | 10 +- src/internal/patching/operator/concatAll.ts | 13 +- src/internal/patching/operator/exhaust.ts | 9 +- src/internal/patching/operator/expand.ts | 8 +- src/internal/patching/operator/mergeAll.ts | 11 +- src/internal/patching/operator/switch.ts | 7 +- src/internal/patching/operator/zipAll.ts | 11 +- 38 files changed, 1184 insertions(+), 741 deletions(-) diff --git a/spec/observables/combineLatest-spec.ts b/spec/observables/combineLatest-spec.ts index 960fdf78ed..313e748676 100644 --- a/spec/observables/combineLatest-spec.ts +++ b/spec/observables/combineLatest-spec.ts @@ -15,18 +15,18 @@ describe('Observable.combineLatest', () => { const expected = '----uv--wx-y--z----|'; const combined = Observable.combineLatest(firstSource, secondSource, - (a: any, b: any) => '' + a + b); + (a, b) => '' + a + b); expectObservable(combined).toBe(expected, {u: 'ad', v: 'ae', w: 'af', x: 'bf', y: 'bg', z: 'cg'}); }); - it('should combine an immediately-scheduled source with an immediately-scheduled second', (done: MochaDone) => { + it('should combine an immediately-scheduled source with an immediately-scheduled second', (done) => { const a = Observable.of(1, 2, 3, queueScheduler); const b = Observable.of(4, 5, 6, 7, 8, queueScheduler); const r = [[1, 4], [2, 4], [2, 5], [3, 5], [3, 6], [3, 7], [3, 8]]; //type definition need to be updated - Observable.combineLatest(a, b, queueScheduler).subscribe((vals: any) => { + Observable.combineLatest(a, b, queueScheduler).subscribe((vals) => { expect(vals).to.deep.equal(r.shift()); }, (x) => { done(new Error('should not be called')); @@ -42,7 +42,7 @@ describe('Observable.combineLatest', () => { const expected = '----uv--wx-y--z----|'; const combined = Observable.combineLatest([firstSource, secondSource], - (a: any, b: any) => '' + a + b); + (a: string, b: string) => '' + a + b); expectObservable(combined).toBe(expected, {u: 'ad', v: 'ae', w: 'af', x: 'bf', y: 'bg', z: 'cg'}); }); @@ -54,7 +54,7 @@ describe('Observable.combineLatest', () => { const e2subs = '^'; const expected = '-'; - const result = Observable.combineLatest(e1, e2, (x: any, y: any) => x + y); + const result = Observable.combineLatest(e1, e2, (x, y) => x + y); expectObservable(result).toBe(expected); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -68,7 +68,7 @@ describe('Observable.combineLatest', () => { const e2subs = '(^!)'; const expected = '-'; - const result = Observable.combineLatest(e1, e2, (x: any, y: any) => x + y); + const result = Observable.combineLatest(e1, e2, (x, y) => x + y); expectObservable(result).toBe(expected); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -82,7 +82,7 @@ describe('Observable.combineLatest', () => { const e2subs = '^'; const expected = '-'; - const result = Observable.combineLatest(e1, e2, (x: any, y: any) => x + y); + const result = Observable.combineLatest(e1, e2, (x, y) => x + y); expectObservable(result).toBe(expected); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -96,7 +96,7 @@ describe('Observable.combineLatest', () => { const e2subs = '(^!)'; const expected = '|'; - const result = Observable.combineLatest(e1, e2, (x: any, y: any) => x + y); + const result = Observable.combineLatest(e1, e2, (x, y) => x + y); expectObservable(result).toBe(expected); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -116,7 +116,7 @@ describe('Observable.combineLatest', () => { const e2subs = '^ !'; const expected = '----|'; - const result = Observable.combineLatest(e1, e2, (x: any, y: any) => x + y); + const result = Observable.combineLatest(e1, e2, (x, y) => x + y); expectObservable(result).toBe(expected, values); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -133,7 +133,7 @@ describe('Observable.combineLatest', () => { const e2subs = '^ !'; const expected = '----|'; - const result = Observable.combineLatest(e2, e1, (x: any, y: any) => x + y); + const result = Observable.combineLatest(e2, e1, (x, y) => x + y); expectObservable(result).toBe(expected, values); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -150,7 +150,7 @@ describe('Observable.combineLatest', () => { const e2subs = '^ '; const expected = '-'; //never - const result = Observable.combineLatest(e1, e2, (x: any, y: any) => x + y); + const result = Observable.combineLatest(e1, e2, (x, y) => x + y); expectObservable(result).toBe(expected, values); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -167,7 +167,7 @@ describe('Observable.combineLatest', () => { const e2subs = '^ !'; const expected = '-----'; //never - const result = Observable.combineLatest(e1, e2, (x: any, y: any) => x + y); + const result = Observable.combineLatest(e1, e2, (x, y) => x + y); expectObservable(result).toBe(expected, values); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -181,7 +181,7 @@ describe('Observable.combineLatest', () => { const e2subs = '^ !'; const expected = '----x-yz--|'; - const result = Observable.combineLatest(e1, e2, (x: any, y: any) => x + y); + const result = Observable.combineLatest(e1, e2, (x, y) => x + y); expectObservable(result).toBe(expected, { x: 'bf', y: 'cf', z: 'cg' }); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -195,7 +195,7 @@ describe('Observable.combineLatest', () => { const e2subs = '^ !'; const expected = '------#'; - const result = Observable.combineLatest(e1, e2, (x: any, y: any) => x + y); + const result = Observable.combineLatest(e1, e2, (x, y) => x + y); expectObservable(result).toBe(expected, null, 'shazbot!'); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -209,7 +209,7 @@ describe('Observable.combineLatest', () => { const e2subs = '^ !'; const expected = '----#'; - const result = Observable.combineLatest(e1, e2, (x: any, y: any) => x + y); + const result = Observable.combineLatest(e1, e2, (x, y) => x + y); expectObservable(result).toBe(expected, null, 'too bad, honk'); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -223,7 +223,7 @@ describe('Observable.combineLatest', () => { const e2subs = '^ !'; const expected = '--#'; - const result = Observable.combineLatest(e1, e2, (x: any, y: any) => x + y); + const result = Observable.combineLatest(e1, e2, (x, y) => x + y); expectObservable(result).toBe(expected, null, 'bazinga'); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -237,7 +237,7 @@ describe('Observable.combineLatest', () => { const e2subs = '^ !'; const expected = '--#'; - const result = Observable.combineLatest(e1, e2, (x: any, y: any) => x + y); + const result = Observable.combineLatest(e1, e2, (x, y) => x + y); expectObservable(result).toBe(expected, null, 'bazinga'); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -251,7 +251,7 @@ describe('Observable.combineLatest', () => { const e2subs = '^ !'; const expected = '--#'; - const result = Observable.combineLatest(e1, e2, (x: any, y: any) => x + y); + const result = Observable.combineLatest(e1, e2, (x, y) => x + y); expectObservable(result).toBe(expected, null, 'bazinga'); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -265,7 +265,7 @@ describe('Observable.combineLatest', () => { const e2subs = '^ !'; const expected = '--#'; - const result = Observable.combineLatest(e1, e2, (x: any, y: any) => x + y); + const result = Observable.combineLatest(e1, e2, (x, y) => x + y); expectObservable(result).toBe(expected, null, 'flurp'); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -279,7 +279,7 @@ describe('Observable.combineLatest', () => { const e2subs = '^ !'; const expected = '--#'; - const result = Observable.combineLatest(e1, e2, (x: any, y: any) => x + y); + const result = Observable.combineLatest(e1, e2, (x, y) => x + y); expectObservable(result).toBe(expected, null, 'flurp'); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -293,7 +293,7 @@ describe('Observable.combineLatest', () => { const e2subs = '^ !'; const expected = '------#'; - const result = Observable.combineLatest(e1, e2, (x: any, y: any) => x + y); + const result = Observable.combineLatest(e1, e2, (x, y) => x + y); expectObservable(result).toBe(expected, null, 'wokka wokka'); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -307,7 +307,7 @@ describe('Observable.combineLatest', () => { const e2subs = '^ !'; const expected = '-----#'; - const result = Observable.combineLatest(e1, e2, (x: any, y: any) => x + y); + const result = Observable.combineLatest(e1, e2, (x, y) => x + y); expectObservable(result).toBe(expected, null, 'wokka wokka'); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -321,7 +321,7 @@ describe('Observable.combineLatest', () => { const e2subs = '^ !'; const expected = '---#'; - const result = Observable.combineLatest(e1, e2, (x: any, y: any) => x + y); + const result = Observable.combineLatest(e1, e2, (x, y) => x + y); expectObservable(result).toBe(expected, { a: 1, b: 2}, 'wokka wokka'); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -335,7 +335,7 @@ describe('Observable.combineLatest', () => { const e2subs = '^ !'; const expected = '---#'; - const result = Observable.combineLatest(e1, e2, (x: any, y: any) => x + y); + const result = Observable.combineLatest(e1, e2, (x, y) => x + y); expectObservable(result).toBe(expected, { a: 1, b: 2}, 'wokka wokka'); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -349,7 +349,7 @@ describe('Observable.combineLatest', () => { const rightSubs = '^ !'; const expected = '---------#'; - const result = Observable.combineLatest(left, right, (x: any, y: any) => x + y); + const result = Observable.combineLatest(left, right, (x, y) => x + y); expectObservable(result).toBe(expected, null, 'bad things'); expectSubscriptions(left.subscriptions).toBe(leftSubs); @@ -363,7 +363,7 @@ describe('Observable.combineLatest', () => { const rightSubs = '^ !'; const expected = '---------#'; - const result = Observable.combineLatest(left, right, (x: any, y: any) => x + y); + const result = Observable.combineLatest(left, right, (x, y) => x + y); expectObservable(result).toBe(expected, null, 'bad things'); expectSubscriptions(left.subscriptions).toBe(leftSubs); @@ -377,7 +377,7 @@ describe('Observable.combineLatest', () => { const e2subs = '^ !'; const expected = '-----x-y-z--|'; - const result = Observable.combineLatest(e1, e2, (x: any, y: any) => x + y); + const result = Observable.combineLatest(e1, e2, (x, y) => x + y); expectObservable(result).toBe(expected, { x: 'be', y: 'ce', z: 'cf' }); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -391,7 +391,7 @@ describe('Observable.combineLatest', () => { const e2subs = '^ !'; const expected = '-----------x--y--z--|'; - const result = Observable.combineLatest(e1, e2, (x: any, y: any) => x + y); + const result = Observable.combineLatest(e1, e2, (x, y) => x + y); expectObservable(result).toBe(expected, { x: 'cd', y: 'ce', z: 'cf' }); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -405,7 +405,7 @@ describe('Observable.combineLatest', () => { const rightSubs = '^ !'; const expected = '---------#'; - const result = Observable.combineLatest(left, right, (x: any, y: any) => x + y); + const result = Observable.combineLatest(left, right, (x, y) => x + y); expectObservable(result).toBe(expected, null, 'jenga'); expectSubscriptions(left.subscriptions).toBe(leftSubs); @@ -419,7 +419,7 @@ describe('Observable.combineLatest', () => { const rightSubs = '^ !'; const expected = '-----------x--y--z--#'; - const result = Observable.combineLatest(left, right, (x: any, y: any) => x + y); + const result = Observable.combineLatest(left, right, (x, y) => x + y); expectObservable(result).toBe(expected, { x: 'cd', y: 'ce', z: 'cf' }, 'dun dun dun'); expectSubscriptions(left.subscriptions).toBe(leftSubs); @@ -433,7 +433,7 @@ describe('Observable.combineLatest', () => { const e2subs = '^ !'; const expected = '---#'; - const result = Observable.combineLatest(e1, e2, (x: any, y: any) => { throw 'ha ha ' + x + ', ' + y; }); + const result = Observable.combineLatest(e1, e2, (x, y) => { throw 'ha ha ' + x + ', ' + y; }); expectObservable(result).toBe(expected, null, 'ha ha 2, 4'); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -449,7 +449,7 @@ describe('Observable.combineLatest', () => { const unsub = ' ! '; const values = { x: 'bf', y: 'cf', z: 'cg' }; - const result = Observable.combineLatest(e1, e2, (x: any, y: any) => x + y); + const result = Observable.combineLatest(e1, e2, (x, y) => x + y); expectObservable(result, unsub).toBe(expected, values); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -466,10 +466,10 @@ describe('Observable.combineLatest', () => { const values = { x: 'bf', y: 'cf', z: 'cg' }; const result = Observable.combineLatest( - e1.mergeMap((x: string) => Observable.of(x)), - e2.mergeMap((x: string) => Observable.of(x)), - (x: any, y: any) => x + y - ).mergeMap((x: any) => Observable.of(x)); + e1.mergeMap((x) => Observable.of(x)), + e2.mergeMap((x) => Observable.of(x)), + (x, y) => x + y + ).mergeMap((x) => Observable.of(x)); expectObservable(result, unsub).toBe(expected, values); expectSubscriptions(e1.subscriptions).toBe(e1subs); diff --git a/spec/observables/concat-spec.ts b/spec/observables/concat-spec.ts index 557059f658..50a6093cc7 100644 --- a/spec/observables/concat-spec.ts +++ b/spec/observables/concat-spec.ts @@ -58,10 +58,10 @@ describe('Observable.concat', () => { const expected = '--i-j-k-l---i-j-'; const unsub = ' !'; - const innerWrapped = inner.mergeMap((x: string) => Observable.of(x)); + const innerWrapped = inner.mergeMap((x) => Observable.of(x)); const result = Observable .concat(innerWrapped, innerWrapped, innerWrapped, innerWrapped) - .mergeMap((x: any) => Observable.of(x)); + .mergeMap((x) => Observable.of(x)); expectObservable(result, unsub).toBe(expected); expectSubscriptions(inner.subscriptions).toBe(innersubs); @@ -334,17 +334,17 @@ describe('Observable.concat', () => { expectSubscriptions(e2.subscriptions).toBe(e2subs); }); - it('should concat an immediately-scheduled source with an immediately-scheduled second', (done: MochaDone) => { + it('should concat an immediately-scheduled source with an immediately-scheduled second', (done) => { const a = Observable.of(1, 2, 3, queueScheduler); const b = Observable.of(4, 5, 6, 7, 8, queueScheduler); const r = [1, 2, 3, 4, 5, 6, 7, 8]; - Observable.concat(a, b, queueScheduler).subscribe((vals: number) => { + Observable.concat(a, b, queueScheduler).subscribe((vals) => { expect(vals).to.equal(r.shift()); }, null, done); }); - it('should use the scheduler even when one Observable is concat\'d', (done: MochaDone) => { + it('should use the scheduler even when one Observable is concat\'d', (done) => { let e1Subscribed = false; const e1 = Observable.defer(() => { e1Subscribed = true; diff --git a/spec/observables/merge-spec.ts b/spec/observables/merge-spec.ts index bba94bf433..40d2d5f574 100644 --- a/spec/observables/merge-spec.ts +++ b/spec/observables/merge-spec.ts @@ -263,7 +263,7 @@ describe('Observable.merge(...observables, Scheduler, number)', () => { expectObservable(Observable.merge(e1, e2, e3, 2, rxTestScheduler)).toBe(expected); }); - it('should use the scheduler even when one Observable is merged', (done: MochaDone) => { + it('should use the scheduler even when one Observable is merged', (done) => { let e1Subscribed = false; const e1 = Observable.defer(() => { e1Subscribed = true; diff --git a/spec/operators/combineAll-spec.ts b/spec/operators/combineAll-spec.ts index d671002121..ba1ceeef15 100644 --- a/spec/operators/combineAll-spec.ts +++ b/spec/operators/combineAll-spec.ts @@ -3,6 +3,7 @@ import * as Rx from '../../src/Rx'; import { hot, cold, expectObservable, expectSubscriptions } from '../helpers/marble-testing'; declare function asDiagram(arg: string): Function; +declare const type: Function; const Observable = Rx.Observable; const queueScheduler = Rx.Scheduler.queue; @@ -15,7 +16,7 @@ describe('Observable.prototype.combineAll', () => { const outer = hot('-x----y--------| ', { x: x, y: y }); const expected = '-----------------A-B--C---|'; - const result = outer.combineAll((a: any, b: any) => String(a) + String(b)); + const result = outer.combineAll((a, b) => String(a) + String(b)); expectObservable(result).toBe(expected, { A: 'a1', B: 'a2', C: 'b2' }); }); @@ -27,7 +28,7 @@ describe('Observable.prototype.combineAll', () => { const e2subs = '^'; const expected = '-'; - const result = Observable.of(e1, e2).combineAll((x: any, y: any) => x + y); + const result = Observable.of(e1, e2).combineAll((x, y) => x + y); expectObservable(result).toBe(expected); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -41,7 +42,7 @@ describe('Observable.prototype.combineAll', () => { const e2subs = '(^!)'; const expected = '-'; - const result = Observable.of(e1, e2).combineAll((x: any, y: any) => x + y); + const result = Observable.of(e1, e2).combineAll((x, y) => x + y); expectObservable(result).toBe(expected); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -55,7 +56,7 @@ describe('Observable.prototype.combineAll', () => { const e2subs = '^'; const expected = '-'; - const result = Observable.of(e1, e2).combineAll((x: any, y: any) => x + y); + const result = Observable.of(e1, e2).combineAll((x, y) => x + y); expectObservable(result).toBe(expected); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -69,7 +70,7 @@ describe('Observable.prototype.combineAll', () => { const e2subs = '(^!)'; const expected = '|'; - const result = Observable.of(e1, e2).combineAll((x: any, y: any) => x + y); + const result = Observable.of(e1, e2).combineAll((x, y) => x + y); expectObservable(result).toBe(expected); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -83,7 +84,7 @@ describe('Observable.prototype.combineAll', () => { const e2subs = '^ !'; const expected = '----|'; - const result = Observable.of(e1, e2).combineAll((x: any, y: any) => x + y); + const result = Observable.of(e1, e2).combineAll((x, y) => x + y); expectObservable(result).toBe(expected); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -97,7 +98,7 @@ describe('Observable.prototype.combineAll', () => { const e2subs = '^ !'; const expected = '----|'; - const result = Observable.of(e2, e1).combineAll((x: any, y: any) => x + y); + const result = Observable.of(e2, e1).combineAll((x, y) => x + y); expectObservable(result).toBe(expected); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -111,7 +112,7 @@ describe('Observable.prototype.combineAll', () => { const e2subs = '^ '; const expected = '-'; //never - const result = Observable.of(e1, e2).combineAll((x: any, y: any) => x + y); + const result = Observable.of(e1, e2).combineAll((x, y) => x + y); expectObservable(result).toBe(expected); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -125,7 +126,7 @@ describe('Observable.prototype.combineAll', () => { const e2subs = '^ !'; const expected = '-----'; //never - const result = Observable.of(e1, e2).combineAll((x: any, y: any) => x + y); + const result = Observable.of(e1, e2).combineAll((x, y) => x + y); expectObservable(result).toBe(expected); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -139,7 +140,7 @@ describe('Observable.prototype.combineAll', () => { const e2subs = '^ !'; const expected = '----x-yz--|'; - const result = Observable.of(e1, e2).combineAll((x: any, y: any) => x + y); + const result = Observable.of(e1, e2).combineAll((x, y) => x + y); expectObservable(result).toBe(expected, { x: 'bf', y: 'cf', z: 'cg' }); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -155,7 +156,7 @@ describe('Observable.prototype.combineAll', () => { const unsub = ' ! '; const values = { x: 'bf', y: 'cf', z: 'cg' }; - const result = Observable.of(e1, e2).combineAll((x: any, y: any) => x + y); + const result = Observable.of(e1, e2).combineAll((x, y) => x + y); expectObservable(result, unsub).toBe(expected, values); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -172,9 +173,9 @@ describe('Observable.prototype.combineAll', () => { const values = { x: 'bf', y: 'cf', z: 'cg' }; const result = Observable.of(e1, e2) - .mergeMap((x: any) => Observable.of(x)) - .combineAll((x: any, y: any) => x + y) - .mergeMap((x: any) => Observable.of(x)); + .mergeMap((x) => Observable.of(x)) + .combineAll((x, y) => x + y) + .mergeMap((x) => Observable.of(x)); expectObservable(result, unsub).toBe(expected, values); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -190,7 +191,7 @@ describe('Observable.prototype.combineAll', () => { const e3subs = '^ !'; const expected = '-----wxyz-|'; - const result = Observable.of(e1, e2, e3).combineAll((x: string, y: string, z: string) => x + y + z); + const result = Observable.of(e1, e2, e3).combineAll((x, y, z) => x + y + z); expectObservable(result).toBe(expected, { w: 'bfi', x: 'cfi', y: 'cgi', z: 'cgj' }); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -205,7 +206,7 @@ describe('Observable.prototype.combineAll', () => { const e2subs = '^ !'; const expected = '------#'; - const result = Observable.of(e1, e2).combineAll((x: any, y: any) => x + y); + const result = Observable.of(e1, e2).combineAll((x, y) => x + y); expectObservable(result).toBe(expected, null, 'shazbot!'); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -219,7 +220,7 @@ describe('Observable.prototype.combineAll', () => { const e2subs = '^ !'; const expected = '----#'; - const result = Observable.of(e1, e2).combineAll((x: any, y: any) => x + y); + const result = Observable.of(e1, e2).combineAll((x, y) => x + y); expectObservable(result).toBe(expected, null, 'too bad, honk'); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -233,7 +234,7 @@ describe('Observable.prototype.combineAll', () => { const e2subs = '^ !'; const expected = '--#'; - const result = Observable.of(e1, e2).combineAll((x: any, y: any) => x + y); + const result = Observable.of(e1, e2).combineAll((x, y) => x + y); expectObservable(result).toBe(expected, null, 'bazinga'); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -247,7 +248,7 @@ describe('Observable.prototype.combineAll', () => { const e2subs = '^ !'; const expected = '--#'; - const result = Observable.of(e1, e2).combineAll((x: any, y: any) => x + y); + const result = Observable.of(e1, e2).combineAll((x, y) => x + y); expectObservable(result).toBe(expected, null, 'bazinga'); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -261,7 +262,7 @@ describe('Observable.prototype.combineAll', () => { const e2subs = '^ !'; const expected = '--#'; - const result = Observable.of(e1, e2).combineAll((x: any, y: any) => x + y); + const result = Observable.of(e1, e2).combineAll((x, y) => x + y); expectObservable(result).toBe(expected, null, 'bazinga'); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -275,7 +276,7 @@ describe('Observable.prototype.combineAll', () => { const e2subs = '^ !'; const expected = '--#'; - const result = Observable.of(e1, e2).combineAll((x: any, y: any) => x + y); + const result = Observable.of(e1, e2).combineAll((x, y) => x + y); expectObservable(result).toBe(expected, null, 'flurp'); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -289,7 +290,7 @@ describe('Observable.prototype.combineAll', () => { const e2subs = '^ !'; const expected = '--#'; - const result = Observable.of(e1, e2).combineAll((x: any, y: any) => x + y); + const result = Observable.of(e1, e2).combineAll((x, y) => x + y); expectObservable(result).toBe(expected, null, 'flurp'); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -303,7 +304,7 @@ describe('Observable.prototype.combineAll', () => { const e2subs = '^ !'; const expected = '------#'; - const result = Observable.of(e1, e2).combineAll((x: any, y: any) => x + y); + const result = Observable.of(e1, e2).combineAll((x, y) => x + y); expectObservable(result).toBe(expected, null, 'wokka wokka'); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -317,7 +318,7 @@ describe('Observable.prototype.combineAll', () => { const e2subs = '^ !'; const expected = '-----#'; - const result = Observable.of(e1, e2).combineAll((x: any, y: any) => x + y); + const result = Observable.of(e1, e2).combineAll((x, y) => x + y); expectObservable(result).toBe(expected, null, 'wokka wokka'); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -331,7 +332,7 @@ describe('Observable.prototype.combineAll', () => { const e2subs = '^ !'; const expected = '---#'; - const result = Observable.of(e1, e2).combineAll((x: any, y: any) => x + y); + const result = Observable.of(e1, e2).combineAll((x, y) => x + y); expectObservable(result).toBe(expected, { a: 1, b: 2}, 'wokka wokka'); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -345,7 +346,7 @@ describe('Observable.prototype.combineAll', () => { const e2subs = '^ !'; const expected = '---#'; - const result = Observable.of(e1, e2).combineAll((x: any, y: any) => x + y); + const result = Observable.of(e1, e2).combineAll((x, y) => x + y); expectObservable(result).toBe(expected, null, 'wokka wokka'); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -359,7 +360,7 @@ describe('Observable.prototype.combineAll', () => { const rightSubs = '^ !'; const expected = '---------#'; - const result = Observable.of(left, right).combineAll((x: any, y: any) => x + y); + const result = Observable.of(left, right).combineAll((x, y) => x + y); expectObservable(result).toBe(expected, null, 'bad things'); expectSubscriptions(left.subscriptions).toBe(leftSubs); @@ -373,7 +374,7 @@ describe('Observable.prototype.combineAll', () => { const rightSubs = '^ !'; const expected = '---------#'; - const result = Observable.of(left, right).combineAll((x: any, y: any) => x + y); + const result = Observable.of(left, right).combineAll((x, y) => x + y); expectObservable(result).toBe(expected, null, 'bad things'); expectSubscriptions(left.subscriptions).toBe(leftSubs); @@ -387,7 +388,7 @@ describe('Observable.prototype.combineAll', () => { const e2subs = '^ !'; const expected = '-----x-y-z--|'; - const result = Observable.of(e1, e2).combineAll((x: any, y: any) => x + y); + const result = Observable.of(e1, e2).combineAll((x, y) => x + y); expectObservable(result).toBe(expected, { x: 'be', y: 'ce', z: 'cf' }); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -401,7 +402,7 @@ describe('Observable.prototype.combineAll', () => { const e2subs = '^ !'; const expected = '-----------x--y--z--|'; - const result = Observable.of(e1, e2).combineAll((x: any, y: any) => x + y); + const result = Observable.of(e1, e2).combineAll((x, y) => x + y); expectObservable(result).toBe(expected, { x: 'cd', y: 'ce', z: 'cf' }); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -415,7 +416,7 @@ describe('Observable.prototype.combineAll', () => { const rightSubs = '^ !'; const expected = '---------#'; - const result = Observable.of(left, right).combineAll((x: any, y: any) => x + y); + const result = Observable.of(left, right).combineAll((x, y) => x + y); expectObservable(result).toBe(expected, null, 'jenga'); expectSubscriptions(left.subscriptions).toBe(leftSubs); @@ -429,7 +430,7 @@ describe('Observable.prototype.combineAll', () => { const rightSubs = '^ !'; const expected = '-----------x--y--z--#'; - const result = Observable.of(left, right).combineAll((x: any, y: any) => x + y); + const result = Observable.of(left, right).combineAll((x, y) => x + y); expectObservable(result).toBe(expected, { x: 'cd', y: 'ce', z: 'cf' }, 'dun dun dun'); expectSubscriptions(left.subscriptions).toBe(leftSubs); @@ -443,18 +444,18 @@ describe('Observable.prototype.combineAll', () => { const e2subs = '^ !'; const expected = '---#'; - const result = Observable.of(e1, e2).combineAll(((x: string, y: string) => { throw 'ha ha ' + x + ', ' + y; })); + const result = Observable.of(e1, e2).combineAll((x, y) => { throw 'ha ha ' + x + ', ' + y; }); expectObservable(result).toBe(expected, null, 'ha ha b, d'); expectSubscriptions(e1.subscriptions).toBe(e1subs); expectSubscriptions(e2.subscriptions).toBe(e2subs); }); - it('should combine two observables', (done: MochaDone) => { + it('should combine two observables', (done) => { const a = Observable.of(1, 2, 3); const b = Observable.of(4, 5, 6, 7, 8); const expected = [[3, 4], [3, 5], [3, 6], [3, 7], [3, 8]]; - Observable.of(a, b).combineAll().subscribe((vals: any) => { + Observable.of(a, b).combineAll().subscribe((vals) => { expect(vals).to.deep.equal(expected.shift()); }, null, () => { expect(expected.length).to.equal(0); @@ -462,17 +463,117 @@ describe('Observable.prototype.combineAll', () => { }); }); - it('should combine two immediately-scheduled observables', (done: MochaDone) => { + it('should combine two immediately-scheduled observables', (done) => { const a = Observable.of(1, 2, 3, queueScheduler); const b = Observable.of(4, 5, 6, 7, 8, queueScheduler); const r = [[1, 4], [2, 4], [2, 5], [3, 5], [3, 6], [3, 7], [3, 8]]; - Observable.of>(a, b, queueScheduler).combineAll() - .subscribe((vals: any) => { + Observable.of(a, b, queueScheduler).combineAll() + .subscribe((vals) => { expect(vals).to.deep.equal(r.shift()); }, null, () => { expect(r.length).to.equal(0); done(); }); }); + + type(() => { + /* tslint:disable:no-unused-variable */ + const source1 = Rx.Observable.of(1, 2, 3); + const source2 = [1, 2, 3]; + const source3 = new Promise(d => d(1)); + + let result: Rx.Observable = Rx.Observable + .of(source1, source2, source3) + .pipe(Rx.operators.combineAll()); + /* tslint:enable:no-unused-variable */ + }); + + type(() => { + /* tslint:disable:no-unused-variable */ + const source1 = Rx.Observable.of(1, 2, 3); + const source2 = [1, 2, 3]; + const source3 = new Promise(d => d(1)); + + let result: Rx.Observable = Rx.Observable + .of(source1, source2, source3) + .pipe(Rx.operators.combineAll((...args) => args.reduce((acc, x) => acc + x, 0))); + /* tslint:enable:no-unused-variable */ + }); + + type(() => { + /* tslint:disable:no-unused-variable */ + const source1 = Rx.Observable.of(1, 2, 3); + const source2 = [1, 2, 3]; + const source3 = new Promise(d => d(1)); + + let result: Rx.Observable = Rx.Observable + .of(source1, source2, source3) + .combineAll(); + /* tslint:enable:no-unused-variable */ + }); + + type(() => { + /* tslint:disable:no-unused-variable */ + const source1 = Rx.Observable.of(1, 2, 3); + const source2 = [1, 2, 3]; + const source3 = new Promise(d => d(1)); + + let result: Rx.Observable = Rx.Observable + .of(source1, source2, source3) + .combineAll((...args) => args.reduce((acc, x) => acc + x, 0)); + /* tslint:enable:no-unused-variable */ + }); + + type(() => { + // coerce type to a specific type + /* tslint:disable:no-unused-variable */ + const source1 = Rx.Observable.of(1, 2, 3); + const source2 = [1, 2, 3]; + const source3 = new Promise(d => d(1)); + + let result: Rx.Observable = Rx.Observable + .of(source1, source2, source3) + .pipe(Rx.operators.combineAll()); + /* tslint:enable:no-unused-variable */ + }); + + type(() => { + // coerce type to a specific type + /* tslint:disable:no-unused-variable */ + const source1 = Rx.Observable.of(1, 2, 3); + const source2 = [1, 2, 3]; + const source3 = new Promise(d => d(1)); + + let result: Rx.Observable = Rx.Observable + .of(source1, source2, source3) + .pipe(Rx.operators.combineAll((...args) => args.reduce((acc, x) => acc + x, 0))); + /* tslint:enable:no-unused-variable */ + }); + + type(() => { + // coerce type to a specific type + /* tslint:disable:no-unused-variable */ + const source1 = Rx.Observable.of(1, 2, 3); + const source2 = [1, 2, 3]; + const source3 = new Promise(d => d(1)); + + let result: Rx.Observable = Rx.Observable + .of(source1, source2, source3) + .combineAll(); + /* tslint:enable:no-unused-variable */ + }); + + type(() => { + // coerce type to a specific type + /* tslint:disable:no-unused-variable */ + const source1 = Rx.Observable.of(1, 2, 3); + const source2 = [1, 2, 3]; + const source3 = new Promise(d => d(1)); + + let result: Rx.Observable = Rx.Observable + .of(source1, source2, source3) + .combineAll((...args) => args.reduce((acc, x) => acc + x, 0)); + /* tslint:enable:no-unused-variable */ + }); }); diff --git a/spec/operators/combineLatest-spec.ts b/spec/operators/combineLatest-spec.ts index 75a83235fd..65b43c5f65 100644 --- a/spec/operators/combineLatest-spec.ts +++ b/spec/operators/combineLatest-spec.ts @@ -12,7 +12,7 @@ describe('Observable.prototype.combineLatest', () => { const e2 = cold('--1--2-3-4---| '); const expected = '--A-BC-D-EF-G-H-|'; - const result = e1.combineLatest(e2, (a: any, b: any) => String(a) + String(b)); + const result = e1.combineLatest(e2, (a, b) => String(a) + String(b)); expectObservable(result).toBe(expected, { A: 'a1', B: 'b1', C: 'b2', D: 'b3', E: 'b4', F: 'c4', G: 'd4', H: 'e4' @@ -26,7 +26,7 @@ describe('Observable.prototype.combineLatest', () => { const e2subs = '^'; const expected = '-'; - const result = e1.combineLatest(e2, (x: any, y: any) => x + y); + const result = e1.combineLatest(e2, (x, y) => x + y); expectObservable(result).toBe(expected); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -40,7 +40,7 @@ describe('Observable.prototype.combineLatest', () => { const e2subs = '(^!)'; const expected = '-'; - const result = e1.combineLatest(e2, (x: any, y: any) => x + y); + const result = e1.combineLatest(e2, (x, y) => x + y); expectObservable(result).toBe(expected); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -54,7 +54,7 @@ describe('Observable.prototype.combineLatest', () => { const e2subs = '^'; const expected = '-'; - const result = e1.combineLatest(e2, (x: any, y: any) => x + y); + const result = e1.combineLatest(e2, (x, y) => x + y); expectObservable(result).toBe(expected); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -68,7 +68,7 @@ describe('Observable.prototype.combineLatest', () => { const e2subs = '(^!)'; const expected = '|'; - const result = e1.combineLatest(e2, (x: any, y: any) => x + y); + const result = e1.combineLatest(e2, (x, y) => x + y); expectObservable(result).toBe(expected); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -88,7 +88,7 @@ describe('Observable.prototype.combineLatest', () => { const e2subs = '^ !'; const expected = '----|'; - const result = e1.combineLatest(e2, (x: any, y: any) => x + y); + const result = e1.combineLatest(e2, (x, y) => x + y); expectObservable(result).toBe(expected, values); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -105,7 +105,7 @@ describe('Observable.prototype.combineLatest', () => { const e2subs = '^ !'; const expected = '----|'; - const result = e2.combineLatest(e1, (x: any, y: any) => x + y); + const result = e2.combineLatest(e1, (x, y) => x + y); expectObservable(result).toBe(expected, values); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -122,7 +122,7 @@ describe('Observable.prototype.combineLatest', () => { const e2subs = '^ '; const expected = '-'; //never - const result = e1.combineLatest(e2, (x: any, y: any) => x + y); + const result = e1.combineLatest(e2, (x, y) => x + y); expectObservable(result).toBe(expected, values); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -139,7 +139,7 @@ describe('Observable.prototype.combineLatest', () => { const e2subs = '^ !'; const expected = '-----'; //never - const result = e1.combineLatest(e2, (x: any, y: any) => x + y); + const result = e1.combineLatest(e2, (x, y) => x + y); expectObservable(result).toBe(expected, values); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -153,7 +153,7 @@ describe('Observable.prototype.combineLatest', () => { const e2subs = '^ !'; const expected = '----x-yz--|'; - const result = e1.combineLatest(e2, (x: any, y: any) => x + y); + const result = e1.combineLatest(e2, (x, y) => x + y); expectObservable(result).toBe(expected, { x: 'bf', y: 'cf', z: 'cg' }); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -184,7 +184,7 @@ describe('Observable.prototype.combineLatest', () => { const e2subs = '^ !'; const expected = '------#'; - const result = e1.combineLatest(e2, (x: any, y: any) => x + y); + const result = e1.combineLatest(e2, (x, y) => x + y); expectObservable(result).toBe(expected, null, 'shazbot!'); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -198,7 +198,7 @@ describe('Observable.prototype.combineLatest', () => { const e2subs = '^ !'; const expected = '----#'; - const result = e1.combineLatest(e2, (x: any, y: any) => x + y); + const result = e1.combineLatest(e2, (x, y) => x + y); expectObservable(result).toBe(expected, null, 'too bad, honk'); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -212,7 +212,7 @@ describe('Observable.prototype.combineLatest', () => { const e2subs = '^ !'; const expected = '--#'; - const result = e1.combineLatest(e2, (x: any, y: any) => x + y); + const result = e1.combineLatest(e2, (x, y) => x + y); expectObservable(result).toBe(expected, null, 'bazinga'); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -226,7 +226,7 @@ describe('Observable.prototype.combineLatest', () => { const e2subs = '^ !'; const expected = '--#'; - const result = e1.combineLatest(e2, (x: any, y: any) => x + y); + const result = e1.combineLatest(e2, (x, y) => x + y); expectObservable(result).toBe(expected, null, 'bazinga'); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -240,7 +240,7 @@ describe('Observable.prototype.combineLatest', () => { const e2subs = '^ !'; const expected = '--#'; - const result = e1.combineLatest(e2, (x: any, y: any) => x + y); + const result = e1.combineLatest(e2, (x, y) => x + y); expectObservable(result).toBe(expected, null, 'bazinga'); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -254,7 +254,7 @@ describe('Observable.prototype.combineLatest', () => { const e2subs = '^ !'; const expected = '--#'; - const result = e1.combineLatest(e2, (x: any, y: any) => x + y); + const result = e1.combineLatest(e2, (x, y) => x + y); expectObservable(result).toBe(expected, null, 'flurp'); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -268,7 +268,7 @@ describe('Observable.prototype.combineLatest', () => { const e2subs = '^ !'; const expected = '--#'; - const result = e1.combineLatest(e2, (x: any, y: any) => x + y); + const result = e1.combineLatest(e2, (x, y) => x + y); expectObservable(result).toBe(expected, null, 'flurp'); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -282,7 +282,7 @@ describe('Observable.prototype.combineLatest', () => { const e2subs = '^ !'; const expected = '------#'; - const result = e1.combineLatest(e2, (x: any, y: any) => x + y); + const result = e1.combineLatest(e2, (x, y) => x + y); expectObservable(result).toBe(expected, null, 'wokka wokka'); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -296,7 +296,7 @@ describe('Observable.prototype.combineLatest', () => { const e2subs = '^ !'; const expected = '-----#'; - const result = e1.combineLatest(e2, (x: any, y: any) => x + y); + const result = e1.combineLatest(e2, (x, y) => x + y); expectObservable(result).toBe(expected, null, 'wokka wokka'); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -310,7 +310,7 @@ describe('Observable.prototype.combineLatest', () => { const e2subs = '^ !'; const expected = '---#'; - const result = e1.combineLatest(e2, (x: any, y: any) => x + y); + const result = e1.combineLatest(e2, (x, y) => x + y); expectObservable(result).toBe(expected, { a: 1, b: 2}, 'wokka wokka'); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -324,7 +324,7 @@ describe('Observable.prototype.combineLatest', () => { const e2subs = '^ !'; const expected = '---#'; - const result = e1.combineLatest(e2, (x: any, y: any) => x + y); + const result = e1.combineLatest(e2, (x, y) => x + y); expectObservable(result).toBe(expected, { a: 1, b: 2}, 'wokka wokka'); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -338,7 +338,7 @@ describe('Observable.prototype.combineLatest', () => { const rightSubs = '^ !'; const expected = '---------#'; - const result = left.combineLatest(right, (x: any, y: any) => x + y); + const result = left.combineLatest(right, (x, y) => x + y); expectObservable(result).toBe(expected, null, 'bad things'); expectSubscriptions(left.subscriptions).toBe(leftSubs); @@ -352,7 +352,7 @@ describe('Observable.prototype.combineLatest', () => { const rightSubs = '^ !'; const expected = '---------#'; - const result = left.combineLatest(right, (x: any, y: any) => x + y); + const result = left.combineLatest(right, (x, y) => x + y); expectObservable(result).toBe(expected, null, 'bad things'); expectSubscriptions(left.subscriptions).toBe(leftSubs); @@ -366,7 +366,7 @@ describe('Observable.prototype.combineLatest', () => { const e2subs = '^ !'; const expected = '-----x-y-z--|'; - const result = e1.combineLatest(e2, (x: any, y: any) => x + y); + const result = e1.combineLatest(e2, (x, y) => x + y); expectObservable(result).toBe(expected, { x: 'be', y: 'ce', z: 'cf' }); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -380,7 +380,7 @@ describe('Observable.prototype.combineLatest', () => { const e2subs = '^ !'; const expected = '-----------x--y--z--|'; - const result = e1.combineLatest(e2, (x: any, y: any) => x + y); + const result = e1.combineLatest(e2, (x, y) => x + y); expectObservable(result).toBe(expected, { x: 'cd', y: 'ce', z: 'cf' }); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -394,7 +394,7 @@ describe('Observable.prototype.combineLatest', () => { const rightSubs = '^ !'; const expected = '---------#'; - const result = left.combineLatest(right, (x: any, y: any) => x + y); + const result = left.combineLatest(right, (x, y) => x + y); expectObservable(result).toBe(expected, null, 'jenga'); expectSubscriptions(left.subscriptions).toBe(leftSubs); @@ -408,7 +408,7 @@ describe('Observable.prototype.combineLatest', () => { const rightSubs = '^ !'; const expected = '-----------x--y--z--#'; - const result = left.combineLatest(right, (x: any, y: any) => x + y); + const result = left.combineLatest(right, (x, y) => x + y); expectObservable(result).toBe(expected, { x: 'cd', y: 'ce', z: 'cf' }, 'dun dun dun'); expectSubscriptions(left.subscriptions).toBe(leftSubs); @@ -422,7 +422,7 @@ describe('Observable.prototype.combineLatest', () => { const e2subs = '^ !'; const expected = '---#'; - const result = e1.combineLatest(e2, (x: number, y: number) => { throw 'ha ha ' + x + ', ' + y; }); + const result = e1.combineLatest(e2, (x, y) => { throw 'ha ha ' + x + ', ' + y; }); expectObservable(result).toBe(expected, null, 'ha ha 2, 4'); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -438,7 +438,7 @@ describe('Observable.prototype.combineLatest', () => { const unsub = ' ! '; const values = { x: 'bf', y: 'cf', z: 'cg' }; - const result = e1.combineLatest(e2, (x: any, y: any) => x + y); + const result = e1.combineLatest(e2, (x, y) => x + y); expectObservable(result, unsub).toBe(expected, values); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -455,9 +455,9 @@ describe('Observable.prototype.combineLatest', () => { const values = { x: 'bf', y: 'cf', z: 'cg' }; const result = e1 - .mergeMap((x: any) => Observable.of(x)) - .combineLatest(e2, (x: any, y: any) => x + y) - .mergeMap((x: any) => Observable.of(x)); + .mergeMap((x) => Observable.of(x)) + .combineLatest(e2, (x, y) => x + y) + .mergeMap((x) => Observable.of(x)); expectObservable(result, unsub).toBe(expected, values); expectSubscriptions(e1.subscriptions).toBe(e1subs); diff --git a/spec/operators/concat-spec.ts b/spec/operators/concat-spec.ts index 9ed6bd8598..10a9afc9fe 100644 --- a/spec/operators/concat-spec.ts +++ b/spec/operators/concat-spec.ts @@ -17,11 +17,10 @@ describe('Observable.prototype.concat', () => { expectObservable(e1.concat(e2, rxTestScheduler)).toBe(expected); }); - it('should work properly with scalar observables', (done: MochaDone) => { - const results = []; + it('should work properly with scalar observables', (done) => { + const results: string[] = []; - const s1 = Observable - .create((observer: Rx.Observer) => { + const s1 = new Observable((observer) => { setTimeout(() => { observer.next(1); observer.complete(); @@ -29,7 +28,7 @@ describe('Observable.prototype.concat', () => { }) .concat(Observable.of(2)); - s1.subscribe((x: number) => { + s1.subscribe((x) => { results.push('Next: ' + x); }, (x) => { done(new Error('should not be called')); @@ -57,7 +56,7 @@ describe('Observable.prototype.concat', () => { const e1 = cold('-'); const e1subs = '^'; const e2 = cold('--|'); - const e2subs = []; + const e2subs: string[] = []; const expected = '-'; expectObservable(e1.concat(e2)).toBe(expected); @@ -81,7 +80,7 @@ describe('Observable.prototype.concat', () => { const e1 = cold('-'); const e1subs = '^'; const e2 = cold('-'); - const e2subs = []; + const e2subs: string[] = []; const expected = '-'; expectObservable(e1.concat(e2)).toBe(expected); @@ -105,7 +104,7 @@ describe('Observable.prototype.concat', () => { const e1 = cold('---#'); const e1subs = '^ !'; const e2 = cold('----|'); - const e2subs = []; + const e2subs: string[] = []; const expected = '---#'; expectObservable(e1.concat(e2)).toBe(expected); @@ -117,7 +116,7 @@ describe('Observable.prototype.concat', () => { const e1 = cold('---#'); const e1subs = '^ !'; const e2 = cold('------#'); - const e2subs = []; + const e2subs: string[] = []; const expected = '---#'; expectObservable(e1.concat(e2)).toBe(expected); @@ -166,7 +165,7 @@ describe('Observable.prototype.concat', () => { const e1 = cold('-'); const e1subs = '^'; const e2 = cold('--a--|'); - const e2subs = []; + const e2subs: string[] = []; const expected = '-'; expectObservable(e1.concat(e2)).toBe(expected); @@ -208,9 +207,9 @@ describe('Observable.prototype.concat', () => { const unsub = ' ! '; const result = e1 - .mergeMap((x: any) => Observable.of(x)) + .mergeMap((x) => Observable.of(x)) .concat(e2) - .mergeMap((x: any) => Observable.of(x)); + .mergeMap((x) => Observable.of(x)); expectObservable(result, unsub).toBe(expected); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -221,7 +220,7 @@ describe('Observable.prototype.concat', () => { const e1 = cold('--#'); const e1subs = '^ !'; const e2 = cold('----a--|'); - const e2subs = []; + const e2subs: string[] = []; const expected = '--#'; expectObservable(e1.concat(e2)).toBe(expected); diff --git a/spec/operators/concatAll-spec.ts b/spec/operators/concatAll-spec.ts index 78af7c36d3..ee687ea878 100644 --- a/spec/operators/concatAll-spec.ts +++ b/spec/operators/concatAll-spec.ts @@ -1,9 +1,10 @@ import { expect } from 'chai'; import * as Rx from '../../src/Rx'; import { hot, cold, expectObservable, expectSubscriptions } from '../helpers/marble-testing'; +import { throwError } from '../../src/internal/observable/throwError'; declare function asDiagram(arg: string): Function; - +declare const type: Function; declare const rxTestScheduler: Rx.TestScheduler; const Observable = Rx.Observable; @@ -21,39 +22,39 @@ describe('Observable.prototype.concatAll', () => { expectObservable(result).toBe(expected); }); - it('should concat sources from promise', function (done: MochaDone) { + it('should concat sources from promise', function (done) { this.timeout(2000); const sources = Rx.Observable.from([ - new Promise((res: any) => { res(0); }), - new Promise((res: any) => { res(1); }), - new Promise((res: any) => { res(2); }), - new Promise((res: any) => { res(3); }), + new Promise((res) => { res(0); }), + new Promise((res) => { res(1); }), + new Promise((res) => { res(2); }), + new Promise((res) => { res(3); }), ]).take(10); - const res = []; - (sources.concatAll()).subscribe( - (x: number) => { res.push(x); }, - (err: any) => { done(new Error('should not be called')); }, + const res: number[] = []; + sources.concatAll().subscribe( + (x) => { res.push(x); }, + (err) => { done(new Error('should not be called')); }, () => { expect(res).to.deep.equal([0, 1, 2, 3]); done(); }); }); - it('should concat and raise error from promise', function (done: MochaDone) { + it('should concat and raise error from promise', function (done) { this.timeout(2000); const sources = Rx.Observable.from([ - new Promise((res: any) => { res(0); }), - new Promise((res: any, rej: any) => { rej(1); }), - new Promise((res: any) => { res(2); }), - new Promise((res: any) => { res(3); }), + new Promise((res) => { res(0); }), + new Promise((res, rej) => { rej(1); }), + new Promise((res) => { res(2); }), + new Promise((res) => { res(3); }), ]).take(10); - const res = []; - (sources.concatAll()).subscribe( - (x: number) => { res.push(x); }, - (err: any) => { + const res: number[] = []; + sources.concatAll().subscribe( + (x) => { res.push(x); }, + (err) => { expect(res.length).to.equal(1); expect(err).to.equal(1); done(); @@ -75,7 +76,7 @@ describe('Observable.prototype.concatAll', () => { it('should throw if any child observable throws', () => { const e1 = Rx.Observable.from([ Rx.Observable.of('a'), - Rx.Observable.throw('error'), + throwError('error'), Rx.Observable.of('c') ]).take(10); const expected = '(a#)'; @@ -137,7 +138,7 @@ describe('Observable.prototype.concatAll', () => { const e1 = cold('-'); const e1subs = '^'; const e2 = cold('--|'); - const e2subs = []; + const e2subs: string[] = []; const expected = '-'; const result = Observable.of(e1, e2).concatAll(); @@ -165,7 +166,7 @@ describe('Observable.prototype.concatAll', () => { const e1 = cold('-'); const e1subs = '^'; const e2 = cold('-'); - const e2subs = []; + const e2subs: string[] = []; const expected = '-'; const result = Observable.of(e1, e2).concatAll(); @@ -193,7 +194,7 @@ describe('Observable.prototype.concatAll', () => { const e1 = cold('---#'); const e1subs = '^ !'; const e2 = cold('----|'); - const e2subs = []; + const e2subs: string[] = []; const expected = '---#'; const result = Observable.of(e1, e2).concatAll(); @@ -207,7 +208,7 @@ describe('Observable.prototype.concatAll', () => { const e1 = cold('---#'); const e1subs = '^ !'; const e2 = cold('------#'); - const e2subs = []; + const e2subs: string[] = []; const expected = '---#'; const result = Observable.of(e1, e2).concatAll(); @@ -264,7 +265,7 @@ describe('Observable.prototype.concatAll', () => { const e1 = cold('-'); const e1subs = '^'; const e2 = cold('--a--|'); - const e2subs = []; + const e2subs: string[] = []; const expected = '-'; const result = Observable.of(e1, e2).concatAll(); @@ -312,9 +313,9 @@ describe('Observable.prototype.concatAll', () => { const unsub = ' ! '; const result = Observable.of(e1, e2) - .mergeMap((x: any) => Observable.of(x)) + .mergeMap((x) => Observable.of(x)) .concatAll() - .mergeMap((x: any) => Observable.of(x)); + .mergeMap((x) => Observable.of(x)); expectObservable(result, unsub).toBe(expected); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -325,7 +326,7 @@ describe('Observable.prototype.concatAll', () => { const e1 = cold('--#'); const e1subs = '^ !'; const e2 = cold('----a--|'); - const e2subs = []; + const e2subs: string[] = []; const expected = '--#'; const result = Observable.of(e1, e2).concatAll(); @@ -372,7 +373,7 @@ describe('Observable.prototype.concatAll', () => { const e2subs = ' ^ !'; const expected = '--a--b--c----x-y-z-|'; - const result = Observable.of>(e1, e2).concatAll(); + const result = Observable.of(e1, e2).concatAll(); expectObservable(result).toBe(expected); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -386,7 +387,7 @@ describe('Observable.prototype.concatAll', () => { const e2subs = ' ^ !'; const expected = '--a--b--c--y--z--|'; - const result = Observable.of>(e1, e2).concatAll(); + const result = Observable.of(e1, e2).concatAll(); expectObservable(result).toBe(expected); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -402,7 +403,7 @@ describe('Observable.prototype.concatAll', () => { const e3subs = ' ^ !'; const expected = '---a---b-----c--|'; - const result = Observable.of>(e1, e2, e3, rxTestScheduler).concatAll(); + const result = Observable.of(e1, e2, e3, rxTestScheduler).concatAll(); expectObservable(result).toBe(expected); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -426,9 +427,59 @@ describe('Observable.prototype.concatAll', () => { const e1subs = '^ !'; const expected = '---a-|'; - const result = Observable.of>(e1, rxTestScheduler).concatAll(); + const result = Observable.of(e1, rxTestScheduler).concatAll(); expectObservable(result).toBe(expected); expectSubscriptions(e1.subscriptions).toBe(e1subs); }); + + type(() => { + /* tslint:disable:no-unused-variable */ + const source1 = Rx.Observable.of(1, 2, 3); + const source2 = [1, 2, 3]; + const source3 = new Promise(d => d(1)); + + let result: Rx.Observable = Rx.Observable + .of(source1, source2, source3) + .pipe(Rx.operators.concatAll()); + /* tslint:enable:no-unused-variable */ + }); + + type(() => { + /* tslint:disable:no-unused-variable */ + const source1 = Rx.Observable.of(1, 2, 3); + const source2 = [1, 2, 3]; + const source3 = new Promise(d => d(1)); + + let result: Rx.Observable = Rx.Observable + .of(source1, source2, source3) + .concatAll(); + /* tslint:enable:no-unused-variable */ + }); + + type(() => { + // coerce type to a specific type + /* tslint:disable:no-unused-variable */ + const source1 = Rx.Observable.of(1, 2, 3); + const source2 = [1, 2, 3]; + const source3 = new Promise(d => d(1)); + + let result: Rx.Observable = Rx.Observable + .of(source1, source2, source3) + .pipe(Rx.operators.concatAll()); + /* tslint:enable:no-unused-variable */ + }); + + type(() => { + // coerce type to a specific type + /* tslint:disable:no-unused-variable */ + const source1 = Rx.Observable.of(1, 2, 3); + const source2 = [1, 2, 3]; + const source3 = new Promise(d => d(1)); + + let result: Rx.Observable = Rx.Observable + .of(source1, source2, source3) + .concatAll(); + /* tslint:enable:no-unused-variable */ + }); }); diff --git a/spec/operators/concatMap-spec.ts b/spec/operators/concatMap-spec.ts index 3331781e51..25a4686a02 100644 --- a/spec/operators/concatMap-spec.ts +++ b/spec/operators/concatMap-spec.ts @@ -16,7 +16,7 @@ describe('Observable.prototype.concatMap', () => { const expected = '--x-x-x-y-y-yz-z-z-|'; const values = {x: 10, y: 30, z: 50}; - const result = e1.concatMap(x => e2.map(i => i * x)); + const result = e1.concatMap(x => e2.map(i => i * parseInt(x))); expectObservable(result).toBe(expected, values); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -36,7 +36,7 @@ describe('Observable.prototype.concatMap', () => { const expected = '--a-a-a-a---b--b--b-------c-c-c-----(d|)'; const observableLookup = { a: a, b: b, c: c, d: d }; - const source = e1.concatMap((value: any) => observableLookup[value]); + const source = e1.concatMap((value) => observableLookup[value]); expectObservable(source).toBe(expected); expectSubscriptions(a.subscriptions).toBe(asubs); @@ -57,7 +57,7 @@ describe('Observable.prototype.concatMap', () => { ' ^ !']; const expected = '---i-j-k-l---i-j-k-l---i-j-k-l---i-j-k-l-|'; - const result = e1.concatMap((value: any) => inner); + const result = e1.concatMap((value) => inner); expectObservable(result).toBe(expected, values); expectSubscriptions(inner.subscriptions).toBe(innersubs); @@ -68,7 +68,7 @@ describe('Observable.prototype.concatMap', () => { const e1 = cold( '|'); const e1subs = '(^!)'; const inner = cold('-1-2-3|'); - const innersubs = []; + const innersubs: string[] = []; const expected = '|'; const result = e1.concatMap(() => inner); @@ -82,7 +82,7 @@ describe('Observable.prototype.concatMap', () => { const e1 = cold( '-'); const e1subs = '^'; const inner = cold('-1-2-3|'); - const innersubs = []; + const innersubs: string[] = []; const expected = '-'; const result = e1.concatMap(() => { return inner; }); @@ -96,7 +96,7 @@ describe('Observable.prototype.concatMap', () => { const e1 = cold( '#'); const e1subs = '(^!)'; const inner = cold('-1-2-3|'); - const innersubs = []; + const innersubs: string[] = []; const expected = '#'; const result = e1.concatMap(() => { return inner; }); @@ -161,7 +161,7 @@ describe('Observable.prototype.concatMap', () => { ' ^ ! ']; const expected = '---i-j-k-l---i-j-k-l---i-j-k-l---i-j-k-l--------|'; - const result = e1.concatMap((value: any) => inner); + const result = e1.concatMap((value) => inner); expectObservable(result).toBe(expected, values); expectSubscriptions(inner.subscriptions).toBe(innersubs); @@ -179,7 +179,7 @@ describe('Observable.prototype.concatMap', () => { ' ^ ! ']; const expected = '---i-j-k-l---i-j-k-l---i-j-k-l---i-j-k-l---------'; - const result = e1.concatMap((value: any) => inner); + const result = e1.concatMap((value) => inner); expectObservable(result).toBe(expected, values); expectSubscriptions(inner.subscriptions).toBe(innersubs); @@ -194,7 +194,7 @@ describe('Observable.prototype.concatMap', () => { const innersubs = ' ^ '; const expected = '---i-j-k-l--------'; - const result = e1.concatMap((value: any) => inner); + const result = e1.concatMap((value) => inner); expectObservable(result).toBe(expected, values); expectSubscriptions(inner.subscriptions).toBe(innersubs); @@ -209,7 +209,7 @@ describe('Observable.prototype.concatMap', () => { const innersubs = ' ^ ! '; const expected = '---i-j-k-l-# '; - const result = e1.concatMap((value: any) => inner); + const result = e1.concatMap((value) => inner); expectObservable(result).toBe(expected, values); expectSubscriptions(inner.subscriptions).toBe(innersubs); @@ -225,7 +225,7 @@ describe('Observable.prototype.concatMap', () => { ' ^ !']; const expected = '---i-j-k-l---i-j-#'; - const result = e1.concatMap((value: any) => inner); + const result = e1.concatMap((value) => inner); expectObservable(result).toBe(expected, values); expectSubscriptions(inner.subscriptions).toBe(innersubs); @@ -240,7 +240,7 @@ describe('Observable.prototype.concatMap', () => { const innersubs = ' ^ ! '; const expected = '---i-j-k-l-# '; - const result = e1.concatMap((value: any) => inner); + const result = e1.concatMap((value) => inner); expectObservable(result).toBe(expected, values); expectSubscriptions(inner.subscriptions).toBe(innersubs); @@ -249,9 +249,9 @@ describe('Observable.prototype.concatMap', () => { it('should concatMap many complex, where all inners are finite', () => { const a = cold( '-# '); - const asubs = []; + const asubs: string[] = []; const b = cold( '-# '); - const bsubs = []; + const bsubs: string[] = []; const c = cold( '-2--3--4--5----6-| '); const csubs = ' ^ ! '; const d = cold( '----2--3| '); @@ -267,7 +267,7 @@ describe('Observable.prototype.concatMap', () => { const expected = '---2--3--4--5----6-----2--3-1------2--3-4-5--------1-2|'; const observableLookup = { a: a, b: b, c: c, d: d, e: e, f: f, g: g }; - const result = e1.concatMap((value: any) => observableLookup[value]); + const result = e1.concatMap((value) => observableLookup[value]); expectObservable(result).toBe(expected); expectSubscriptions(a.subscriptions).toBe(asubs); @@ -282,25 +282,25 @@ describe('Observable.prototype.concatMap', () => { it('should concatMap many complex, all inners finite except one', () => { const a = cold( '-# '); - const asubs = []; + const asubs: string[] = []; const b = cold( '-# '); - const bsubs = []; + const bsubs: string[] = []; const c = cold( '-2--3--4--5----6-| '); const csubs = ' ^ ! '; const d = cold( '----2--3- '); const dsubs = ' ^ '; const e = cold( '-1------2--3-4-5---| '); - const esubs = []; + const esubs: string[] = []; const f = cold( '--| '); - const fsubs = []; + const fsubs: string[] = []; const g = cold( '---1-2|'); - const gsubs = []; + const gsubs: string[] = []; const e1 = hot('-a-b--^-c-----d------e----------------f-----g| '); const e1subs = '^ '; const expected = '---2--3--4--5----6-----2--3----------------------------'; const observableLookup = { a: a, b: b, c: c, d: d, e: e, f: f, g: g }; - const result = e1.concatMap((value: any) => observableLookup[value]); + const result = e1.concatMap((value) => observableLookup[value]); expectObservable(result).toBe(expected); expectSubscriptions(a.subscriptions).toBe(asubs); @@ -315,9 +315,9 @@ describe('Observable.prototype.concatMap', () => { it('should concatMap many complex, inners finite, outer does not complete', () => { const a = cold( '-# '); - const asubs = []; + const asubs: string[] = []; const b = cold( '-# '); - const bsubs = []; + const bsubs: string[] = []; const c = cold( '-2--3--4--5----6-| '); const csubs = ' ^ ! '; const d = cold( '----2--3| '); @@ -333,7 +333,7 @@ describe('Observable.prototype.concatMap', () => { const expected = '---2--3--4--5----6-----2--3-1------2--3-4-5--------1-2-'; const observableLookup = { a: a, b: b, c: c, d: d, e: e, f: f, g: g }; - const result = e1.concatMap((value: any) => observableLookup[value]); + const result = e1.concatMap((value) => observableLookup[value]); expectObservable(result).toBe(expected); expectSubscriptions(a.subscriptions).toBe(asubs); @@ -348,9 +348,9 @@ describe('Observable.prototype.concatMap', () => { it('should concatMap many complex, all inners finite, and outer throws', () => { const a = cold( '-# '); - const asubs = []; + const asubs: string[] = []; const b = cold( '-# '); - const bsubs = []; + const bsubs: string[] = []; const c = cold( '-2--3--4--5----6-| '); const csubs = ' ^ ! '; const d = cold( '----2--3| '); @@ -358,15 +358,15 @@ describe('Observable.prototype.concatMap', () => { const e = cold( '-1------2--3-4-5---| '); const esubs = ' ^ ! '; const f = cold( '--| '); - const fsubs = []; + const fsubs: string[] = []; const g = cold( '---1-2|'); - const gsubs = []; + const gsubs: string[] = []; const e1 = hot('-a-b--^-c-----d------e----------------f-----g# '); const e1subs = '^ ! '; const expected = '---2--3--4--5----6-----2--3-1------2--3# '; const observableLookup = { a: a, b: b, c: c, d: d, e: e, f: f, g: g }; - const result = e1.concatMap((value: any) => observableLookup[value]); + const result = e1.concatMap((value) => observableLookup[value]); expectObservable(result).toBe(expected); expectSubscriptions(a.subscriptions).toBe(asubs); @@ -381,25 +381,25 @@ describe('Observable.prototype.concatMap', () => { it('should concatMap many complex, all inners complete except one throws', () => { const a = cold( '-# '); - const asubs = []; + const asubs: string[] = []; const b = cold( '-# '); - const bsubs = []; + const bsubs: string[] = []; const c = cold( '-2--3--4--5----6-# '); const csubs = ' ^ ! '; const d = cold( '----2--3| '); - const dsubs = []; + const dsubs: string[] = []; const e = cold( '-1------2--3-4-5---| '); - const esubs = []; + const esubs: string[] = []; const f = cold( '--| '); - const fsubs = []; + const fsubs: string[] = []; const g = cold( '---1-2|'); - const gsubs = []; + const gsubs: string[] = []; const e1 = hot('-a-b--^-c-----d------e----------------f-----g| '); const e1subs = '^ ! '; const expected = '---2--3--4--5----6-# '; const observableLookup = { a: a, b: b, c: c, d: d, e: e, f: f, g: g }; - const result = e1.concatMap((value: any) => observableLookup[value]); + const result = e1.concatMap((value) => observableLookup[value]); expectObservable(result).toBe(expected); expectSubscriptions(a.subscriptions).toBe(asubs); @@ -414,9 +414,9 @@ describe('Observable.prototype.concatMap', () => { it('should concatMap many complex, all inners finite, outer is unsubscribed early', () => { const a = cold( '-# '); - const asubs = []; + const asubs: string[] = []; const b = cold( '-# '); - const bsubs = []; + const bsubs: string[] = []; const c = cold( '-2--3--4--5----6-| '); const csubs = ' ^ ! '; const d = cold( '----2--3| '); @@ -424,16 +424,16 @@ describe('Observable.prototype.concatMap', () => { const e = cold( '-1------2--3-4-5---| '); const esubs = ' ^ ! '; const f = cold( '--| '); - const fsubs = []; + const fsubs: string[] = []; const g = cold( '---1-2|'); - const gsubs = []; + const gsubs: string[] = []; const e1 = hot('-a-b--^-c-----d------e----------------f-----g| '); const e1subs = '^ ! '; const unsub = ' ! '; const expected = '---2--3--4--5----6-----2--3-1-- '; const observableLookup = { a: a, b: b, c: c, d: d, e: e, f: f, g: g }; - const result = e1.concatMap((value: any) => observableLookup[value]); + const result = e1.concatMap((value) => observableLookup[value]); expectObservable(result, unsub).toBe(expected); expectSubscriptions(a.subscriptions).toBe(asubs); @@ -448,9 +448,9 @@ describe('Observable.prototype.concatMap', () => { it('should not break unsubscription chains when result is unsubscribed explicitly', () => { const a = cold( '-# '); - const asubs = []; + const asubs: string[] = []; const b = cold( '-# '); - const bsubs = []; + const bsubs: string[] = []; const c = cold( '-2--3--4--5----6-| '); const csubs = ' ^ ! '; const d = cold( '----2--3| '); @@ -458,9 +458,9 @@ describe('Observable.prototype.concatMap', () => { const e = cold( '-1------2--3-4-5---| '); const esubs = ' ^ ! '; const f = cold( '--| '); - const fsubs = []; + const fsubs: string[] = []; const g = cold( '---1-2|'); - const gsubs = []; + const gsubs: string[] = []; const e1 = hot('-a-b--^-c-----d------e----------------f-----g| '); const e1subs = '^ ! '; const unsub = ' ! '; @@ -468,9 +468,9 @@ describe('Observable.prototype.concatMap', () => { const observableLookup = { a: a, b: b, c: c, d: d, e: e, f: f, g: g }; const result = e1 - .mergeMap((x: any) => Observable.of(x)) - .concatMap((value: any) => observableLookup[value]) - .mergeMap((x: any) => Observable.of(x)); + .mergeMap((x) => Observable.of(x)) + .concatMap((value) => observableLookup[value]) + .mergeMap((x) => Observable.of(x)); expectObservable(result, unsub).toBe(expected); expectSubscriptions(a.subscriptions).toBe(asubs); @@ -485,25 +485,25 @@ describe('Observable.prototype.concatMap', () => { it('should concatMap many complex, all inners finite, project throws', () => { const a = cold( '-# '); - const asubs = []; + const asubs: string[] = []; const b = cold( '-# '); - const bsubs = []; + const bsubs: string[] = []; const c = cold( '-2--3--4--5----6-| '); const csubs = ' ^ ! '; const d = cold( '----2--3| '); const dsubs = ' ^ ! '; const e = cold( '-1------2--3-4-5---| '); - const esubs = []; + const esubs: string[] = []; const f = cold( '--| '); - const fsubs = []; + const fsubs: string[] = []; const g = cold( '---1-2|'); - const gsubs = []; + const gsubs: string[] = []; const e1 = hot('-a-b--^-c-----d------e----------------f-----g| '); const e1subs = '^ ! '; const expected = '---2--3--4--5----6-----2--3# '; const observableLookup = { a: a, b: b, c: c, d: d, e: e, f: f, g: g }; - const result = e1.concatMap((value: string) => { + const result = e1.concatMap((value) => { if (value === 'e') { throw 'error'; } return observableLookup[value]; }); @@ -519,7 +519,7 @@ describe('Observable.prototype.concatMap', () => { expectSubscriptions(e1.subscriptions).toBe(e1subs); }); - function arrayRepeat(value, times) { + function arrayRepeat(value: string, times: number) { let results = []; for (let i = 0; i < times; i++) { results.push(value); @@ -532,7 +532,7 @@ describe('Observable.prototype.concatMap', () => { const e1subs = '^ !'; const expected = '(22)--(4444)---(333)----(22)----|'; - const result = e1.concatMap(((value: any) => arrayRepeat(value, value))); + const result = e1.concatMap((value) => arrayRepeat(value, +value)); expectObservable(result).toBe(expected); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -543,8 +543,8 @@ describe('Observable.prototype.concatMap', () => { const e1subs = '^ !'; const expected = '(44)--(8888)---(666)----(44)----|'; - const result = e1.concatMap(((value: any) => arrayRepeat(value, value)), - (x: string, y: string) => String(parseInt(x) + parseInt(y))); + const result = e1.concatMap((value) => arrayRepeat(value, +value), + (x, y) => String(parseInt(x) + parseInt(y))); expectObservable(result).toBe(expected); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -555,7 +555,7 @@ describe('Observable.prototype.concatMap', () => { const e1subs = '^ !'; const expected = '(22)--(4444)---(333)----(22)----#'; - const result = e1.concatMap(((value: any) => arrayRepeat(value, value))); + const result = e1.concatMap((value) => arrayRepeat(value, +value)); expectObservable(result).toBe(expected); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -566,8 +566,8 @@ describe('Observable.prototype.concatMap', () => { const e1subs = '^ !'; const expected = '(44)--(8888)---(666)----(44)----#'; - const result = e1.concatMap(((value: any) => arrayRepeat(value, value)), - (x: string, y: string) => String(parseInt(x) + parseInt(y))); + const result = e1.concatMap((value) => arrayRepeat(value, +value), + (x, y) => String(parseInt(x) + parseInt(y))); expectObservable(result).toBe(expected); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -579,7 +579,7 @@ describe('Observable.prototype.concatMap', () => { const unsub = ' ! '; const expected = '(22)--(4444)-- '; - const result = e1.concatMap(((value: any) => arrayRepeat(value, value))); + const result = e1.concatMap((value) => arrayRepeat(value, +value)); expectObservable(result, unsub).toBe(expected); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -591,8 +591,8 @@ describe('Observable.prototype.concatMap', () => { const unsub = ' ! '; const expected = '(44)--(8888)-- '; - const result = e1.concatMap(((value: any) => arrayRepeat(value, value)), - (x: string, y: string) => String(parseInt(x) + parseInt(y))); + const result = e1.concatMap((value) => arrayRepeat(value, +value), + (x, y) => String(parseInt(x) + parseInt(y))); expectObservable(result, unsub).toBe(expected); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -604,13 +604,13 @@ describe('Observable.prototype.concatMap', () => { const expected = '(22)--(4444)---# '; let invoked = 0; - const result = e1.concatMap(((value: any) => { + const result = e1.concatMap((value) => { invoked++; if (invoked === 3) { throw 'error'; } - return arrayRepeat(value, value); - })); + return arrayRepeat(value, +value); + }); expectObservable(result).toBe(expected); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -621,8 +621,8 @@ describe('Observable.prototype.concatMap', () => { const e1subs = '^ ! '; const expected = '(44)--(8888)---# '; - const result = e1.concatMap(((value: any) => arrayRepeat(value, value)), - (inner: any, outer: any) => { + const result = e1.concatMap((value) => arrayRepeat(value, +value), + (inner, outer) => { if (outer === '3') { throw 'error'; } @@ -639,13 +639,13 @@ describe('Observable.prototype.concatMap', () => { const expected = '(44)--(8888)---# '; let invoked = 0; - const result = e1.concatMap(((value: any) => { + const result = e1.concatMap((value) => { invoked++; if (invoked === 3) { throw 'error'; } - return arrayRepeat(value, value); - }), (inner: string, outer: string) => { + return arrayRepeat(value, +value); + }, (inner, outer) => { return String(parseInt(outer) + parseInt(inner)); }); @@ -653,15 +653,15 @@ describe('Observable.prototype.concatMap', () => { expectSubscriptions(e1.subscriptions).toBe(e1subs); }); - it('should map values to constant resolved promises and concatenate', (done: MochaDone) => { + it('should map values to constant resolved promises and concatenate', (done) => { const source = Rx.Observable.from([4, 3, 2, 1]); - const project = (value: any) => Observable.from(Promise.resolve(42)); + const project = (value: number) => Observable.from(Promise.resolve(42)); - const results = []; + const results: number[] = []; source.concatMap(project).subscribe( - (x: any) => { + (x) => { results.push(x); - }, (err: any) => { + }, (err) => { done(new Error('Subscriber error handler not supposed to be called.')); }, () => { expect(results).to.deep.equal([42, 42, 42, 42]); @@ -669,14 +669,14 @@ describe('Observable.prototype.concatMap', () => { }); }); - it('should map values to constant rejected promises and concatenate', (done: MochaDone) => { + it('should map values to constant rejected promises and concatenate', (done) => { const source = Rx.Observable.from([4, 3, 2, 1]); const project = (value: any) => Observable.from(Promise.reject(42)); source.concatMap(project).subscribe( - (x: any) => { + (x) => { done(new Error('Subscriber next handler not supposed to be called.')); - }, (err: any) => { + }, (err) => { expect(err).to.deep.equal(42); done(); }, () => { @@ -684,15 +684,15 @@ describe('Observable.prototype.concatMap', () => { }); }); - it('should map values to resolved promises and concatenate', (done: MochaDone) => { + it('should map values to resolved promises and concatenate', (done) => { const source = Rx.Observable.from([4, 3, 2, 1]); const project = (value: number, index: number) => Observable.from(Promise.resolve(value + index)); - const results = []; + const results: number[] = []; source.concatMap(project).subscribe( - (x: any) => { + (x) => { results.push(x); - }, (err: any) => { + }, (err) => { done(new Error('Subscriber error handler not supposed to be called.')); }, () => { expect(results).to.deep.equal([4, 4, 4, 4]); @@ -700,14 +700,14 @@ describe('Observable.prototype.concatMap', () => { }); }); - it('should map values to rejected promises and concatenate', (done: MochaDone) => { + it('should map values to rejected promises and concatenate', (done) => { const source = Rx.Observable.from([4, 3, 2, 1]); const project = (value: number, index: number) => Observable.from(Promise.reject('' + value + '-' + index)); source.concatMap(project).subscribe( - (x: any) => { + (x) => { done(new Error('Subscriber next handler not supposed to be called.')); - }, (err: any) => { + }, (err) => { expect(err).to.deep.equal('4-0'); done(); }, () => { @@ -715,17 +715,17 @@ describe('Observable.prototype.concatMap', () => { }); }); - it('should concatMap values to resolved promises with resultSelector', (done: MochaDone) => { + it('should concatMap values to resolved promises with resultSelector', (done) => { const source = Rx.Observable.from([4, 3, 2, 1]); - const resultSelectorCalledWith = []; + const resultSelectorCalledWith: number[][] = []; const project = (value: number, index: number) => Observable.from((Promise.resolve([value, index]))); - const resultSelector = function (outerVal, innerVal, outerIndex, innerIndex) { + const resultSelector = function (outerVal: any, innerVal: any, outerIndex: any, innerIndex: any): number { resultSelectorCalledWith.push([].slice.call(arguments)); return 8; }; - const results = []; + const results: number[] = []; const expectedCalls = [ [4, [4, 0], 0, 0], [3, [3, 1], 1, 0], @@ -733,9 +733,9 @@ describe('Observable.prototype.concatMap', () => { [1, [1, 3], 3, 0] ]; source.concatMap(project, resultSelector).subscribe( - (x: any) => { + (x) => { results.push(x); - }, (err: any) => { + }, (err) => { done(new Error('Subscriber error handler not supposed to be called.')); }, () => { expect(results).to.deep.equal([8, 8, 8, 8]); @@ -744,7 +744,7 @@ describe('Observable.prototype.concatMap', () => { }); }); - it('should concatMap values to rejected promises with resultSelector', (done: MochaDone) => { + it('should concatMap values to rejected promises with resultSelector', (done) => { const source = Rx.Observable.from([4, 3, 2, 1]); const project = (value: number, index: number) => Observable.from(Promise.reject('' + value + '-' + index)); @@ -753,9 +753,9 @@ describe('Observable.prototype.concatMap', () => { }; source.concatMap(project, resultSelector).subscribe( - (x: any) => { + (x) => { done(new Error('Subscriber next handler not supposed to be called.')); - }, (err: any) => { + }, (err) => { expect(err).to.deep.equal('4-0'); done(); }, () => { diff --git a/spec/operators/concatMapTo-spec.ts b/spec/operators/concatMapTo-spec.ts index d17dea93ca..63b88a2cac 100644 --- a/spec/operators/concatMapTo-spec.ts +++ b/spec/operators/concatMapTo-spec.ts @@ -44,7 +44,7 @@ describe('Observable.prototype.concatMapTo', () => { const e1 = cold( '|'); const e1subs = '(^!)'; const inner = cold('-1-2-3|'); - const innersubs = []; + const innersubs: string[] = []; const expected = '|'; const result = e1.concatMapTo(inner); @@ -58,7 +58,7 @@ describe('Observable.prototype.concatMapTo', () => { const e1 = cold( '-'); const e1subs = '^'; const inner = cold('-1-2-3|'); - const innersubs = []; + const innersubs: string[] = []; const expected = '-'; const result = e1.concatMapTo(inner); @@ -72,7 +72,7 @@ describe('Observable.prototype.concatMapTo', () => { const e1 = cold( '#'); const e1subs = '(^!)'; const inner = cold('-1-2-3|'); - const innersubs = []; + const innersubs: string[] = []; const expected = '#'; const result = e1.concatMapTo(inner); @@ -173,9 +173,9 @@ describe('Observable.prototype.concatMapTo', () => { const unsub = ' !'; const result = e1 - .mergeMap((x: any) => Observable.of(x)) + .mergeMap((x) => Observable.of(x)) .concatMapTo(inner) - .mergeMap((x: any) => Observable.of(x)); + .mergeMap((x) => Observable.of(x)); expectObservable(result, unsub).toBe(expected, values); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -257,7 +257,7 @@ describe('Observable.prototype.concatMapTo', () => { const expected = '(2345)(4567)---(3456)---(2345)--|'; const result = e1.concatMapTo(['0', '1', '2', '3'], - (x: string, y: string) => String(parseInt(x) + parseInt(y))); + (x, y) => String(parseInt(x) + parseInt(y))); expectObservable(result).toBe(expected); }); @@ -276,7 +276,7 @@ describe('Observable.prototype.concatMapTo', () => { const expected = '(2345)(4567)---(3456)---(2345)--#'; const result = e1.concatMapTo(['0', '1', '2', '3'], - (x: string, y: string) => String(parseInt(x) + parseInt(y))); + (x, y) => String(parseInt(x) + parseInt(y))); expectObservable(result).toBe(expected); }); @@ -297,7 +297,7 @@ describe('Observable.prototype.concatMapTo', () => { const expected = '(2345)(4567)--'; const result = e1.concatMapTo(['0', '1', '2', '3'], - (x: string, y: string) => String(parseInt(x) + parseInt(y))); + (x, y) => String(parseInt(x) + parseInt(y))); expectObservable(result, unsub).toBe(expected); }); @@ -306,7 +306,7 @@ describe('Observable.prototype.concatMapTo', () => { const e1 = hot('2-----4--------3--------2-------|'); const expected = '(2345)(4567)---#'; - const result = e1.concatMapTo(['0', '1', '2', '3'], (x: string, y: string) => { + const result = e1.concatMapTo(['0', '1', '2', '3'], (x, y) => { if (x === '3') { throw 'error'; } @@ -316,15 +316,15 @@ describe('Observable.prototype.concatMapTo', () => { expectObservable(result).toBe(expected); }); - it('should map values to constant resolved promises and concatenate', (done: MochaDone) => { + it('should map values to constant resolved promises and concatenate', (done) => { const source = Rx.Observable.from([4, 3, 2, 1]); - const results = []; + const results: number[] = []; source.concatMapTo(Observable.from(Promise.resolve(42))).subscribe( - (x: any) => { + (x) => { results.push(x); }, - (err: any) => { + (err) => { done(new Error('Subscriber error handler not supposed to be called.')); }, () => { @@ -333,14 +333,14 @@ describe('Observable.prototype.concatMapTo', () => { }); }); - it('should map values to constant rejected promises and concatenate', (done: MochaDone) => { + it('should map values to constant rejected promises and concatenate', (done) => { const source = Rx.Observable.from([4, 3, 2, 1]); source.concatMapTo(Observable.from(Promise.reject(42))).subscribe( - (x: any) => { + (x) => { done(new Error('Subscriber next handler not supposed to be called.')); }, - (err: any) => { + (err) => { expect(err).to.equal(42); done(); }, @@ -349,16 +349,16 @@ describe('Observable.prototype.concatMapTo', () => { }); }); - it('should concatMapTo values to resolved promises with resultSelector', (done: MochaDone) => { + it('should concatMapTo values to resolved promises with resultSelector', (done) => { const source = Rx.Observable.from([4, 3, 2, 1]); - const resultSelectorCalledWith = []; + const resultSelectorCalledWith: number[][] = []; const inner = Observable.from(Promise.resolve(42)); - const resultSelector = function (outerVal, innerVal, outerIndex, innerIndex) { + const resultSelector = function (outerVal: number, innerVal: number, outerIndex: number, innerIndex: number) { resultSelectorCalledWith.push([].slice.call(arguments)); return 8; }; - const results = []; + const results: number[] = []; const expectedCalls = [ [4, 42, 0, 0], [3, 42, 1, 0], @@ -366,10 +366,10 @@ describe('Observable.prototype.concatMapTo', () => { [1, 42, 3, 0] ]; source.concatMapTo(inner, resultSelector).subscribe( - (x: any) => { + (x) => { results.push(x); }, - (err: any) => { + (err) => { done(new Error('Subscriber error handler not supposed to be called.')); }, () => { @@ -379,7 +379,7 @@ describe('Observable.prototype.concatMapTo', () => { }); }); - it('should concatMapTo values to rejected promises with resultSelector', (done: MochaDone) => { + it('should concatMapTo values to rejected promises with resultSelector', (done) => { const source = Rx.Observable.from([4, 3, 2, 1]); const inner = Observable.from(Promise.reject(42)); const resultSelector = () => { @@ -387,10 +387,10 @@ describe('Observable.prototype.concatMapTo', () => { }; source.concatMapTo(inner, resultSelector).subscribe( - (x: any) => { + (x) => { done(new Error('Subscriber next handler not supposed to be called.')); }, - (err: any) => { + (err) => { expect(err).to.equal(42); done(); }, diff --git a/spec/operators/exhaust-spec.ts b/spec/operators/exhaust-spec.ts index 48d0035813..029efa591a 100644 --- a/spec/operators/exhaust-spec.ts +++ b/spec/operators/exhaust-spec.ts @@ -3,6 +3,7 @@ import * as Rx from '../../src/Rx'; import { hot, cold, expectObservable, expectSubscriptions } from '../helpers/marble-testing'; declare function asDiagram(arg: string): Function; +declare const type: Function; const Observable = Rx.Observable; @@ -15,17 +16,17 @@ describe('Observable.prototype.exhaust', () => { const e1 = hot( '------x-------y-----z-------------|', { x: x, y: y, z: z }); const expected = '--------a---b---c------g--h---i---|'; - expectObservable((e1).exhaust()).toBe(expected); + expectObservable(e1.exhaust()).toBe(expected); }); it('should switch to first immediately-scheduled inner Observable', () => { const e1 = cold( '(ab|)'); const e1subs = '(^!)'; const e2 = cold( '(cd|)'); - const e2subs = []; + const e2subs: string[] = []; const expected = '(ab|)'; - expectObservable((Observable.of(e1, e2)).exhaust()).toBe(expected); + expectObservable(Observable.of(e1, e2).exhaust()).toBe(expected); expectSubscriptions(e1.subscriptions).toBe(e1subs); expectSubscriptions(e2.subscriptions).toBe(e2subs); }); @@ -35,7 +36,7 @@ describe('Observable.prototype.exhaust', () => { const e1subs = '(^!)'; const expected = '#'; - expectObservable((e1).exhaust()).toBe(expected); + expectObservable(e1.exhaust()).toBe(expected); expectSubscriptions(e1.subscriptions).toBe(e1subs); }); @@ -44,7 +45,7 @@ describe('Observable.prototype.exhaust', () => { const e1subs = '(^!)'; const expected = '|'; - expectObservable((e1).exhaust()).toBe(expected); + expectObservable(e1.exhaust()).toBe(expected); expectSubscriptions(e1.subscriptions).toBe(e1subs); }); @@ -53,7 +54,7 @@ describe('Observable.prototype.exhaust', () => { const e1subs = '^'; const expected = '-'; - expectObservable((e1).exhaust()).toBe(expected); + expectObservable(e1.exhaust()).toBe(expected); expectSubscriptions(e1.subscriptions).toBe(e1subs); }); @@ -61,13 +62,13 @@ describe('Observable.prototype.exhaust', () => { const x = cold( '--a---b---c--| '); const xsubs = ' ^ ! '; const y = cold( '---d--e---f---| '); - const ysubs = []; + const ysubs: string[] = []; const z = cold( '---g--h---i---|'); const zsubs = ' ^ !'; const e1 = hot( '------x-------y-----z-------------|', { x: x, y: y, z: z }); const expected = '--------a---b---c------g--h---i---|'; - expectObservable((e1).exhaust()).toBe(expected); + expectObservable(e1.exhaust()).toBe(expected); expectSubscriptions(x.subscriptions).toBe(xsubs); expectSubscriptions(y.subscriptions).toBe(ysubs); expectSubscriptions(z.subscriptions).toBe(zsubs); @@ -77,12 +78,12 @@ describe('Observable.prototype.exhaust', () => { const x = cold( '--a---b---c--| '); const xsubs = ' ^ ! '; const y = cold( '---d--e---f---|'); - const ysubs = []; + const ysubs: string[] = []; const e1 = hot( '------x-------y------| ', { x: x, y: y }); const unsub = ' ! '; const expected = '--------a---b--- '; - expectObservable((e1).exhaust(), unsub).toBe(expected); + expectObservable(e1.exhaust(), unsub).toBe(expected); expectSubscriptions(x.subscriptions).toBe(xsubs); expectSubscriptions(y.subscriptions).toBe(ysubs); }); @@ -91,15 +92,15 @@ describe('Observable.prototype.exhaust', () => { const x = cold( '--a---b---c--| '); const xsubs = ' ^ ! '; const y = cold( '---d--e---f---|'); - const ysubs = []; + const ysubs: string[] = []; const e1 = hot( '------x-------y------| ', { x: x, y: y }); const unsub = ' ! '; const expected = '--------a---b---- '; - const result = (e1) - .mergeMap((x: any) => Observable.of(x)) + const result = e1 + .mergeMap((x) => Observable.of(x)) .exhaust() - .mergeMap((x: any) => Observable.of(x)); + .mergeMap((x) => Observable.of(x)); expectObservable(result, unsub).toBe(expected); expectSubscriptions(x.subscriptions).toBe(xsubs); @@ -110,13 +111,13 @@ describe('Observable.prototype.exhaust', () => { const x = cold( '--a---b--| '); const xsubs = ' ^ ! '; const y = cold( '-d---e- '); - const ysubs = []; + const ysubs: string[] = []; const z = cold( '---f--g---h--'); const zsubs = ' ^ '; const e1 = hot( '---x---y------z----------| ', { x: x, y: y, z: z }); const expected = '-----a---b-------f--g---h--'; - expectObservable((e1).exhaust()).toBe(expected); + expectObservable(e1.exhaust()).toBe(expected); expectSubscriptions(x.subscriptions).toBe(xsubs); expectSubscriptions(y.subscriptions).toBe(ysubs); expectSubscriptions(z.subscriptions).toBe(zsubs); @@ -126,11 +127,11 @@ describe('Observable.prototype.exhaust', () => { const x = cold( '--a---b---c--| '); const xsubs = ' ^ ! '; const y = cold( '---d--e---f---| '); - const ysubs = []; + const ysubs: string[] = []; const e1 = hot( '------(xy)------------|', { x: x, y: y }); const expected = '--------a---b---c-----|'; - expectObservable((e1).exhaust()).toBe(expected); + expectObservable(e1.exhaust()).toBe(expected); expectSubscriptions(x.subscriptions).toBe(xsubs); expectSubscriptions(y.subscriptions).toBe(ysubs); }); @@ -139,11 +140,11 @@ describe('Observable.prototype.exhaust', () => { const x = cold( '--a---# '); const xsubs = ' ^ ! '; const y = cold( '---d--e---f---|'); - const ysubs = []; + const ysubs: string[] = []; const e1 = hot( '------x-------y------| ', { x: x, y: y }); const expected = '--------a---# '; - expectObservable((e1).exhaust()).toBe(expected); + expectObservable(e1.exhaust()).toBe(expected); expectSubscriptions(x.subscriptions).toBe(xsubs); expectSubscriptions(y.subscriptions).toBe(ysubs); }); @@ -152,11 +153,11 @@ describe('Observable.prototype.exhaust', () => { const x = cold( '--a---b---c--| '); const xsubs = ' ^ ! '; const y = cold( '---d--e---f---|'); - const ysubs = []; + const ysubs: string[] = []; const e1 = hot( '------x-------y-------# ', { x: x, y: y }); const expected = '--------a---b---c-----# '; - expectObservable((e1).exhaust()).toBe(expected); + expectObservable(e1.exhaust()).toBe(expected); expectSubscriptions(x.subscriptions).toBe(xsubs); expectSubscriptions(y.subscriptions).toBe(ysubs); }); @@ -166,7 +167,7 @@ describe('Observable.prototype.exhaust', () => { const e1subs = '^ !'; const expected = '------|'; - expectObservable((e1).exhaust()).toBe(expected); + expectObservable(e1.exhaust()).toBe(expected); expectSubscriptions(e1.subscriptions).toBe(e1subs); }); @@ -175,7 +176,7 @@ describe('Observable.prototype.exhaust', () => { const e1subs = '^'; const expected = '-'; - expectObservable((e1).exhaust()).toBe(expected); + expectObservable(e1.exhaust()).toBe(expected); expectSubscriptions(e1.subscriptions).toBe(e1subs); }); @@ -185,16 +186,16 @@ describe('Observable.prototype.exhaust', () => { const e1 = hot( '------x---------------|', { x: x }); const expected = '--------a---b---c-----|'; - expectObservable((e1).exhaust()).toBe(expected); + expectObservable(e1.exhaust()).toBe(expected); expectSubscriptions(x.subscriptions).toBe(xsubs); }); - it('should handle an observable of promises', (done: MochaDone) => { + it('should handle an observable of promises', (done) => { const expected = [1]; - (Observable.of(Promise.resolve(1), Promise.resolve(2), Promise.resolve(3))) + Observable.of(Promise.resolve(1), Promise.resolve(2), Promise.resolve(3)) .exhaust() - .subscribe((x: number) => { + .subscribe((x) => { expect(x).to.equal(expected.shift()); }, null, () => { expect(expected.length).to.equal(0); @@ -202,16 +203,66 @@ describe('Observable.prototype.exhaust', () => { }); }); - it('should handle an observable of promises, where one rejects', (done: MochaDone) => { - (Observable.of(Promise.reject(2), Promise.resolve(1))) + it('should handle an observable of promises, where one rejects', (done) => { + Observable.of(Promise.reject(2), Promise.resolve(1)) .exhaust() - .subscribe((x: any) => { + .subscribe((x) => { done(new Error('should not be called')); - }, (err: any) => { + }, (err) => { expect(err).to.equal(2); done(); }, () => { done(new Error('should not be called')); }); }); + + type(() => { + /* tslint:disable:no-unused-variable */ + const source1 = Rx.Observable.of(1, 2, 3); + const source2 = [1, 2, 3]; + const source3 = new Promise(d => d(1)); + + let result: Rx.Observable = Rx.Observable + .of(source1, source2, source3) + .pipe(Rx.operators.exhaust()); + /* tslint:enable:no-unused-variable */ + }); + + type(() => { + /* tslint:disable:no-unused-variable */ + const source1 = Rx.Observable.of(1, 2, 3); + const source2 = [1, 2, 3]; + const source3 = new Promise(d => d(1)); + + let result: Rx.Observable = Rx.Observable + .of(source1, source2, source3) + .exhaust(); + /* tslint:enable:no-unused-variable */ + }); + + type(() => { + // coerce type to a specific type + /* tslint:disable:no-unused-variable */ + const source1 = Rx.Observable.of(1, 2, 3); + const source2 = [1, 2, 3]; + const source3 = new Promise(d => d(1)); + + let result: Rx.Observable = Rx.Observable + .of(source1, source2, source3) + .pipe(Rx.operators.exhaust()); + /* tslint:enable:no-unused-variable */ + }); + + type(() => { + // coerce type to a specific type + /* tslint:disable:no-unused-variable */ + const source1 = Rx.Observable.of(1, 2, 3); + const source2 = [1, 2, 3]; + const source3 = new Promise(d => d(1)); + + let result: Rx.Observable = Rx.Observable + .of(source1, source2, source3) + .exhaust(); + /* tslint:enable:no-unused-variable */ + }); }); diff --git a/spec/operators/exhaustMap-spec.ts b/spec/operators/exhaustMap-spec.ts index a5f9706e04..3b4162dd8b 100644 --- a/spec/operators/exhaustMap-spec.ts +++ b/spec/operators/exhaustMap-spec.ts @@ -15,7 +15,7 @@ describe('Observable.prototype.exhaustMap', () => { const expected = '--x-x-x-y-y-y------|'; const values = {x: 10, y: 30, z: 50}; - const result = e1.exhaustMap(x => e2.map(i => i * x)); + const result = e1.exhaustMap(x => e2.map(i => i * +x)); expectObservable(result).toBe(expected, values); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -23,12 +23,12 @@ describe('Observable.prototype.exhaustMap', () => { it('should handle outer throw', () => { const x = cold('--a--b--c--|'); - const xsubs = []; + const xsubs: string[] = []; const e1 = cold('#'); const e1subs = '(^!)'; const expected = '#'; - const result = (e1).exhaustMap(() => x); + const result = e1.exhaustMap(() => x); expectObservable(result).toBe(expected); expectSubscriptions(x.subscriptions).toBe(xsubs); @@ -37,12 +37,12 @@ describe('Observable.prototype.exhaustMap', () => { it('should handle outer empty', () => { const x = cold('--a--b--c--|'); - const xsubs = []; + const xsubs: string[] = []; const e1 = cold('|'); const e1subs = '(^!)'; const expected = '|'; - const result = (e1).exhaustMap(() => x); + const result = e1.exhaustMap(() => x); expectObservable(result).toBe(expected); expectSubscriptions(x.subscriptions).toBe(xsubs); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -50,12 +50,12 @@ describe('Observable.prototype.exhaustMap', () => { it('should handle outer never', () => { const x = cold('--a--b--c--|'); - const xsubs = []; + const xsubs: string[] = []; const e1 = cold('-'); const e1subs = '^'; const expected = '-'; - const result = (e1).exhaustMap(() => x); + const result = e1.exhaustMap(() => x); expectObservable(result).toBe(expected); expectSubscriptions(x.subscriptions).toBe(xsubs); @@ -67,7 +67,7 @@ describe('Observable.prototype.exhaustMap', () => { const e1subs = '^ !'; const expected = '---#'; - const result = (e1).exhaustMap((value: any) => { + const result = e1.exhaustMap((value) => { throw 'error'; }); @@ -82,7 +82,7 @@ describe('Observable.prototype.exhaustMap', () => { const e1subs = '^ ! '; const expected = '-----# '; - const result = (e1).exhaustMap((value: any) => x, + const result = e1.exhaustMap((value) => x, () => { throw 'error'; }); @@ -96,7 +96,7 @@ describe('Observable.prototype.exhaustMap', () => { const x = cold( '--a--b--c--| '); const xsubs = ' ^ ! '; const y = cold( '--d--e--f--| '); - const ysubs = []; + const ysubs: string[] = []; const z = cold( '--g--h--i--| '); const zsubs = ' ^ ! '; const e1 = hot('---x---------y-----------------z-------------|'); @@ -105,7 +105,7 @@ describe('Observable.prototype.exhaustMap', () => { const observableLookup = { x: x, y: y, z: z }; - const result = (e1).exhaustMap((value: any) => observableLookup[value]); + const result = e1.exhaustMap((value) => observableLookup[value]); expectObservable(result).toBe(expected); expectSubscriptions(x.subscriptions).toBe(xsubs); @@ -118,7 +118,7 @@ describe('Observable.prototype.exhaustMap', () => { const x = cold( '--a--b--c--| '); const xsubs = ' ^ ! '; const y = cold( '--d--e--f--| '); - const ysubs = []; + const ysubs: string[] = []; const z = cold( '--g--h--i--| '); const zsubs = ' ^ ! '; const e1 = hot('---x---------y-----------------z-------------|'); @@ -128,7 +128,7 @@ describe('Observable.prototype.exhaustMap', () => { const observableLookup = { x: x, y: y, z: z }; - const result = (e1).exhaustMap((value: any) => observableLookup[value]); + const result = e1.exhaustMap((value) => observableLookup[value]); expectObservable(result, unsub).toBe(expected); expectSubscriptions(x.subscriptions).toBe(xsubs); @@ -141,7 +141,7 @@ describe('Observable.prototype.exhaustMap', () => { const x = cold( '--a--b--c--| '); const xsubs = ' ^ ! '; const y = cold( '--d--e--f--| '); - const ysubs = []; + const ysubs: string[] = []; const z = cold( '--g--h--i--| '); const zsubs = ' ^ ! '; const e1 = hot('---x---------y-----------------z-------------|'); @@ -151,10 +151,10 @@ describe('Observable.prototype.exhaustMap', () => { const observableLookup = { x: x, y: y, z: z }; - const result = (e1) - .mergeMap((x: any) => Observable.of(x)) - .exhaustMap((value: any) => observableLookup[value]) - .mergeMap((x: any) => Observable.of(x)); + const result = e1 + .mergeMap((x) => Observable.of(x)) + .exhaustMap((value) => observableLookup[value]) + .mergeMap((x) => Observable.of(x)); expectObservable(result, unsub).toBe(expected); expectSubscriptions(x.subscriptions).toBe(xsubs); @@ -167,7 +167,7 @@ describe('Observable.prototype.exhaustMap', () => { const x = cold( '--a--b--c--| '); const xsubs = ' ^ ! '; const y = cold( '--d--e--f--| '); - const ysubs = []; + const ysubs: string[] = []; const z = cold( '--g--h--i-----'); const zsubs = ' ^ '; const e1 = hot('---x---------y-----------------z---------| '); @@ -176,7 +176,7 @@ describe('Observable.prototype.exhaustMap', () => { const observableLookup = { x: x, y: y, z: z }; - const result = (e1).exhaustMap((value: any) => observableLookup[value]); + const result = e1.exhaustMap((value) => observableLookup[value]); expectObservable(result).toBe(expected); expectSubscriptions(x.subscriptions).toBe(xsubs); @@ -189,14 +189,14 @@ describe('Observable.prototype.exhaustMap', () => { const x = cold( '--a--b--c--d--e--| '); const xsubs = ' ^ ! '; const y = cold( '---f---g---h---i--| '); - const ysubs = []; + const ysubs: string[] = []; const e1 = hot('---------(xy)----------------|'); const e1subs = '^ !'; const expected = '-----------a--b--c--d--e-----|'; const observableLookup = { x: x, y: y }; - const result = (e1).exhaustMap((value: any) => observableLookup[value]); + const result = e1.exhaustMap((value) => observableLookup[value]); expectObservable(result).toBe(expected); expectSubscriptions(x.subscriptions).toBe(xsubs); @@ -208,14 +208,14 @@ describe('Observable.prototype.exhaustMap', () => { const x = cold( '--a--b--c--d--# '); const xsubs = ' ^ ! '; const y = cold( '---f---g---h---i--'); - const ysubs = []; + const ysubs: string[] = []; const e1 = hot('---------x---------y---------| '); const e1subs = '^ ! '; const expected = '-----------a--b--c--d--# '; const observableLookup = { x: x, y: y }; - const result = (e1).exhaustMap((value: any) => observableLookup[value]); + const result = e1.exhaustMap((value) => observableLookup[value]); expectObservable(result).toBe(expected); expectSubscriptions(x.subscriptions).toBe(xsubs); @@ -227,7 +227,7 @@ describe('Observable.prototype.exhaustMap', () => { const x = hot('-----a--b--c--d--e--| '); const xsubs = ' ^ ! '; const y = hot('--p-o-o-p-------f---g---h---i--| '); - const ysubs = []; + const ysubs: string[] = []; const z = hot('---z-o-o-m-------------j---k---l---m--|'); const zsubs = ' ^ !'; const e1 = hot('---------x----y-----z--------| '); @@ -236,7 +236,7 @@ describe('Observable.prototype.exhaustMap', () => { const observableLookup = { x: x, y: y, z: z }; - const result = (e1).exhaustMap((value: any) => observableLookup[value]); + const result = e1.exhaustMap((value) => observableLookup[value]); expectObservable(result).toBe(expected); expectSubscriptions(x.subscriptions).toBe(xsubs); @@ -256,7 +256,7 @@ describe('Observable.prototype.exhaustMap', () => { const observableLookup = { x: x, y: y }; - const result = (e1).exhaustMap((value: any) => observableLookup[value]); + const result = e1.exhaustMap((value) => observableLookup[value]); expectObservable(result).toBe(expected); expectSubscriptions(x.subscriptions).toBe(xsubs); @@ -275,7 +275,7 @@ describe('Observable.prototype.exhaustMap', () => { const observableLookup = { x: x, y: y }; - const result = (e1).exhaustMap((value: any) => observableLookup[value]); + const result = e1.exhaustMap((value) => observableLookup[value]); expectObservable(result).toBe(expected); expectSubscriptions(x.subscriptions).toBe(xsubs); @@ -287,14 +287,14 @@ describe('Observable.prototype.exhaustMap', () => { const x = cold('-'); const y = cold('#'); const xsubs = ' ^ '; - const ysubs = []; + const ysubs: string[] = []; const e1 = hot('---------x---------y----------|'); const e1subs = '^ '; const expected = '-------------------------------'; const observableLookup = { x: x, y: y }; - const result = (e1).exhaustMap((value: any) => observableLookup[value]); + const result = e1.exhaustMap((value) => observableLookup[value]); expectObservable(result).toBe(expected); expectSubscriptions(x.subscriptions).toBe(xsubs); @@ -313,7 +313,7 @@ describe('Observable.prototype.exhaustMap', () => { const observableLookup = { x: x, y: y }; - const result = (e1).exhaustMap((value: any) => observableLookup[value]); + const result = e1.exhaustMap((value) => observableLookup[value]); expectObservable(result).toBe(expected); expectSubscriptions(x.subscriptions).toBe(xsubs); @@ -330,7 +330,7 @@ describe('Observable.prototype.exhaustMap', () => { const observableLookup = { x: x }; - const result = (e1).exhaustMap((value: any) => observableLookup[value]); + const result = e1.exhaustMap((value) => observableLookup[value]); expectObservable(result).toBe(expected); expectSubscriptions(x.subscriptions).toBe(xsubs); @@ -341,7 +341,7 @@ describe('Observable.prototype.exhaustMap', () => { const x = cold( '--a--b--c--d--e-| '); const xsubs = ' ^ ! '; const y = cold( '---f---g---h---i--| '); - const ysubs = []; + const ysubs: string[] = []; const z = cold( '---k---l---m---n--|'); const zsubs = ' ^ !'; const e1 = hot('--x---------y------z-| '); @@ -362,7 +362,7 @@ describe('Observable.prototype.exhaustMap', () => { n: ['z', 'n', 1, 3], }; - const result = (e1).exhaustMap((value: any) => observableLookup[value], + const result = e1.exhaustMap((value) => observableLookup[value], (innerValue, outerValue, innerIndex, outerIndex) => [innerValue, outerValue, innerIndex, outerIndex]); expectObservable(result).toBe(expected, expectedValues); diff --git a/spec/operators/expand-spec.ts b/spec/operators/expand-spec.ts index 72d2b20c37..a2b44b6162 100644 --- a/spec/operators/expand-spec.ts +++ b/spec/operators/expand-spec.ts @@ -1,10 +1,11 @@ import { expect } from 'chai'; import * as Rx from '../../src/Rx'; import { hot, cold, expectObservable, expectSubscriptions } from '../helpers/marble-testing'; +import { Subscribable } from '../../src/internal/Observable'; declare function asDiagram(arg: string): Function; +declare const type: Function; -declare const Symbol: any; declare const rxTestScheduler: Rx.TestScheduler; const Observable = Rx.Observable; @@ -64,7 +65,7 @@ describe('Observable.prototype.expand', () => { a--b--c--d--(e|) */ - const result = e1.expand((x: any, index: number): Rx.Observable => { + const result = e1.expand((x, index): Rx.Observable => { if (x === 16) { return Observable.empty(); } else { @@ -89,9 +90,9 @@ describe('Observable.prototype.expand', () => { const e2shape = '---(z|) '; const expected = 'a--b--c--(d#)'; - const result = e1.expand((x: number) => { + const result = e1.expand((x) => { if (x === 8) { - return cold('#'); + return cold('#'); } return cold(e2shape, { z: x + x }); }); @@ -113,7 +114,7 @@ describe('Observable.prototype.expand', () => { const e2shape = '---(z|) '; const expected = 'a--b--c--(d#)'; - const result = e1.expand((x: number) => { + const result = e1.expand((x) => { if (x === 8) { throw 'error'; } @@ -138,7 +139,7 @@ describe('Observable.prototype.expand', () => { const e2shape = '---(z|) '; const expected = 'a--b--c- '; - const result = e1.expand((x: number): Rx.Observable => { + const result = e1.expand((x): Rx.Observable => { if (x === 16) { return Observable.empty(); } @@ -163,15 +164,15 @@ describe('Observable.prototype.expand', () => { const expected = 'a--b--c- '; const unsub = ' ! '; - const result = (e1) - .mergeMap((x: any) => Observable.of(x)) - .expand((x: number): Rx.Observable => { + const result = e1 + .mergeMap((x) => Observable.of(x)) + .expand((x): Rx.Observable => { if (x === 16) { return Observable.empty(); } return cold(e2shape, { z: x + x }); }) - .mergeMap((x: any) => Observable.of(x)); + .mergeMap((x) => Observable.of(x)); expectObservable(result, unsub).toBe(expected, values); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -190,7 +191,7 @@ describe('Observable.prototype.expand', () => { const e2shape = '---(z|) '; const expected = 'a-ab-bc-cd-de-(e|)'; - const result = e1.expand((x: number): Rx.Observable => { + const result = e1.expand((x): Rx.Observable => { if (x === 16) { return Observable.empty(); } @@ -228,7 +229,7 @@ describe('Observable.prototype.expand', () => { const expected = 'a--u--b--v--c--x--d--y--(ez|)'; const concurrencyLimit = 1; - const result = e1.expand((x: number): Rx.Observable => { + const result = e1.expand((x): Rx.Observable => { if (x === 16 || x === 160) { return Observable.empty(); } @@ -261,7 +262,7 @@ describe('Observable.prototype.expand', () => { const expected = 'a---a-u---b-b---v-(cc)(x|)'; const concurrencyLimit = 2; - const result = e1.expand((x: number): Rx.Observable => { + const result = e1.expand((x): Rx.Observable => { if (x === 4 || x === 40) { return Observable.empty(); } @@ -291,7 +292,7 @@ describe('Observable.prototype.expand', () => { const expected = 'a-ub-vc-xd-ye-(z|)'; const concurrencyLimit = 100; - const result = e1.expand((x: number): Rx.Observable => { + const result = e1.expand((x): Rx.Observable => { if (x === 16 || x === 160) { return Observable.empty(); } @@ -314,7 +315,7 @@ describe('Observable.prototype.expand', () => { const e1subs = '(^!)'; const expected = '(abcde|)'; - const result = e1.expand((x: number) => { + const result = e1.expand((x) => { if (x === 16) { return Observable.empty(); } @@ -325,16 +326,16 @@ describe('Observable.prototype.expand', () => { expectSubscriptions(e1.subscriptions).toBe(e1subs); }); - it('should recursively flatten promises', (done: MochaDone) => { + it('should recursively flatten promises', (done) => { const expected = [1, 2, 4, 8, 16]; Observable.of(1) - .expand((x: number): any => { + .expand((x): any => { if (x === 16) { return Observable.empty(); } return Promise.resolve(x + x); }) - .subscribe((x: number) => { + .subscribe((x) => { expect(x).to.equal(expected.shift()); }, null, () => { expect(expected.length).to.equal(0); @@ -342,16 +343,16 @@ describe('Observable.prototype.expand', () => { }); }); - it('should recursively flatten Arrays', (done: MochaDone) => { + it('should recursively flatten Arrays', (done) => { const expected = [1, 2, 4, 8, 16]; Observable.of(1) - .expand((x: number): any => { + .expand((x): any => { if (x === 16) { return Observable.empty(); } return [x + x]; }) - .subscribe((x: number) => { + .subscribe((x) => { expect(x).to.equal(expected.shift()); }, null, () => { expect(expected.length).to.equal(0); @@ -359,11 +360,11 @@ describe('Observable.prototype.expand', () => { }); }); - it('should recursively flatten lowercase-o observables', (done: MochaDone) => { + it('should recursively flatten lowercase-o observables', (done) => { const expected = [1, 2, 4, 8, 16]; - const project = (x: any, index: number) => { + const project = (x: number, index: number): Subscribable => { if (x === 16) { - return Observable.empty(); + return Observable.empty(); } const ish = { @@ -376,12 +377,12 @@ describe('Observable.prototype.expand', () => { ish[Symbol.observable] = function () { return this; }; - return ish; + return > ish; }; - (Observable.of(1)) + Observable.of(1) .expand(project) - .subscribe((x: number) => { + .subscribe((x) => { expect(x).to.equal(expected.shift()); }, null, () => { expect(expected.length).to.equal(0); diff --git a/spec/operators/merge-spec.ts b/spec/operators/merge-spec.ts index 060b40c84d..b278006482 100644 --- a/spec/operators/merge-spec.ts +++ b/spec/operators/merge-spec.ts @@ -24,12 +24,12 @@ describe('Observable.prototype.merge', () => { expectSubscriptions(e2.subscriptions).toBe(e2subs); }); - it('should merge a source with a second', (done: MochaDone) => { + it('should merge a source with a second', (done) => { const a = Observable.of(1, 2, 3); const b = Observable.of(4, 5, 6, 7, 8); const r = [1, 2, 3, 4, 5, 6, 7, 8]; - a.merge(b).subscribe((val: number) => { + a.merge(b).subscribe((val) => { expect(val).to.equal(r.shift()); }, (x) => { done(new Error('should not be called')); @@ -38,12 +38,12 @@ describe('Observable.prototype.merge', () => { }); }); - it('should merge an immediately-scheduled source with an immediately-scheduled second', (done: MochaDone) => { + it('should merge an immediately-scheduled source with an immediately-scheduled second', (done) => { const a = Observable.of(1, 2, 3, queueScheduler); const b = Observable.of(4, 5, 6, 7, 8, queueScheduler); const r = [1, 2, 4, 3, 5, 6, 7, 8]; - a.merge(b, queueScheduler).subscribe((val: number) => { + a.merge(b, queueScheduler).subscribe((val) => { expect(val).to.equal(r.shift()); }, (x) => { done(new Error('should not be called')); @@ -132,9 +132,9 @@ describe('Observable.prototype.merge', () => { const unsub = ' ! '; const result = e1 - .map((x: string) => x) + .map((x) => x) .merge(e2, rxTestScheduler) - .map((x: string) => x); + .map((x) => x); expectObservable(result, unsub).toBe(expected); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -279,22 +279,22 @@ describe('Observable.prototype.merge', () => { }); describe('Observable.prototype.mergeAll', () => { - it('should merge two observables', (done: MochaDone) => { + it('should merge two observables', (done) => { const a = Observable.of(1, 2, 3); const b = Observable.of(4, 5, 6, 7, 8); const r = [1, 2, 3, 4, 5, 6, 7, 8]; - Observable.of(a, b).mergeAll().subscribe((val: number) => { + Observable.of(a, b).mergeAll().subscribe((val) => { expect(val).to.equal(r.shift()); }, null, done); }); - it('should merge two immediately-scheduled observables', (done: MochaDone) => { + it('should merge two immediately-scheduled observables', (done) => { const a = Observable.of(1, 2, 3, queueScheduler); const b = Observable.of(4, 5, 6, 7, 8, queueScheduler); const r = [1, 2, 4, 3, 5, 6, 7, 8]; - Observable.of>(a, b, queueScheduler).mergeAll().subscribe((val: number) => { + Observable.of(a, b, queueScheduler).mergeAll().subscribe((val) => { expect(val).to.equal(r.shift()); }, null, done); }); diff --git a/spec/operators/mergeAll-spec.ts b/spec/operators/mergeAll-spec.ts index 0483d79621..f1dd71a7e1 100644 --- a/spec/operators/mergeAll-spec.ts +++ b/spec/operators/mergeAll-spec.ts @@ -1,8 +1,10 @@ import { expect } from 'chai'; import * as Rx from '../../src/Rx'; import { hot, cold, expectObservable, expectSubscriptions } from '../helpers/marble-testing'; +import { throwError } from '../../src/internal/observable/throwError'; declare function asDiagram(arg: string): Function; +declare const type: Function; const Observable = Rx.Observable; @@ -31,7 +33,7 @@ describe('Observable.prototype.mergeAll', () => { it('should throw if any child observable throws', () => { const e1 = Observable.from([ Observable.of('a'), - Observable.throw('error'), + throwError('error'), Observable.of('c') ]); const expected = '(a#)'; @@ -146,10 +148,10 @@ describe('Observable.prototype.mergeAll', () => { const expected = '--a--db--ec-- '; const unsub = ' ! '; - const result = (e1) - .mergeMap((x: string) => Observable.of(x)) + const result = e1 + .mergeMap((x) => Observable.of(x)) .mergeAll() - .mergeMap((x: any) => Observable.of(x)); + .mergeMap((x) => Observable.of(x)); expectObservable(result, unsub).toBe(expected); expectSubscriptions(x.subscriptions).toBe(xsubs); @@ -346,7 +348,7 @@ describe('Observable.prototype.mergeAll', () => { const y = cold( 'c-d-e-f-# '); const ysubs = ' ^ ! '; const z = cold( 'g-h-i-j-k-|'); - const zsubs = []; + const zsubs: string[] = []; const e1 = hot('--x---------y--------z--------| ', { x: x, y: y, z: z }); const e1subs = '^ ! '; const expected = '--a-b-------c-d-e-f-# '; @@ -373,42 +375,92 @@ describe('Observable.prototype.mergeAll', () => { expectSubscriptions(e1.subscriptions).toBe(e1subs); }); - it('should merge all promises in an observable', (done: MochaDone) => { + it('should merge all promises in an observable', (done) => { const e1 = Rx.Observable.from([ - new Promise((res: any) => { res('a'); }), - new Promise((res: any) => { res('b'); }), - new Promise((res: any) => { res('c'); }), - new Promise((res: any) => { res('d'); }), + new Promise((res) => { res('a'); }), + new Promise((res) => { res('b'); }), + new Promise((res) => { res('c'); }), + new Promise((res) => { res('d'); }), ]); const expected = ['a', 'b', 'c', 'd']; - const res = []; - (e1.mergeAll()).subscribe( - (x: any) => { res.push(x); }, - (err: any) => { done(new Error('should not be called')); }, + const res: string[] = []; + e1.mergeAll().subscribe( + (x) => { res.push(x); }, + (err) => { done(new Error('should not be called')); }, () => { expect(res).to.deep.equal(expected); done(); }); }); - it('should raise error when promise rejects', (done: MochaDone) => { + it('should raise error when promise rejects', (done) => { const error = 'error'; const e1 = Rx.Observable.from([ - new Promise((res: any) => { res('a'); }), - new Promise((res: any, rej: any) => { rej(error); }), - new Promise((res: any) => { res('c'); }), - new Promise((res: any) => { res('d'); }), + new Promise((res) => { res('a'); }), + new Promise((res: any, rej) => { rej(error); }), + new Promise((res) => { res('c'); }), + new Promise((res) => { res('d'); }), ]); - const res = []; - (e1.mergeAll()).subscribe( - (x: any) => { res.push(x); }, - (err: any) => { + const res: string[] = []; + e1.mergeAll().subscribe( + (x) => { res.push(x); }, + (err) => { expect(res.length).to.equal(1); expect(err).to.equal('error'); done(); }, () => { done(new Error('should not be called')); }); }); + + type(() => { + /* tslint:disable:no-unused-variable */ + const source1 = Rx.Observable.of(1, 2, 3); + const source2 = [1, 2, 3]; + const source3 = new Promise(d => d(1)); + + let result: Rx.Observable = Rx.Observable + .of(source1, source2, source3) + .pipe(Rx.operators.mergeAll()); + /* tslint:enable:no-unused-variable */ + }); + + type(() => { + /* tslint:disable:no-unused-variable */ + const source1 = Rx.Observable.of(1, 2, 3); + const source2 = [1, 2, 3]; + const source3 = new Promise(d => d(1)); + + let result: Rx.Observable = Rx.Observable + .of(source1, source2, source3) + .mergeAll(); + /* tslint:enable:no-unused-variable */ + }); + + type(() => { + // coerce type to a specific type + /* tslint:disable:no-unused-variable */ + const source1 = Rx.Observable.of(1, 2, 3); + const source2 = [1, 2, 3]; + const source3 = new Promise(d => d(1)); + + let result: Rx.Observable = Rx.Observable + .of(source1, source2, source3) + .pipe(Rx.operators.mergeAll()); + /* tslint:enable:no-unused-variable */ + }); + + type(() => { + // coerce type to a specific type + /* tslint:disable:no-unused-variable */ + const source1 = Rx.Observable.of(1, 2, 3); + const source2 = [1, 2, 3]; + const source3 = new Promise(d => d(1)); + + let result: Rx.Observable = Rx.Observable + .of(source1, source2, source3) + .mergeAll(); + /* tslint:enable:no-unused-variable */ + }); }); diff --git a/spec/operators/mergeMap-spec.ts b/spec/operators/mergeMap-spec.ts index b803c35d69..4aaecef9d3 100644 --- a/spec/operators/mergeMap-spec.ts +++ b/spec/operators/mergeMap-spec.ts @@ -17,7 +17,7 @@ describe('Observable.prototype.mergeMap', () => { const expected = '--x-x-x-y-yzyz-z---|'; const values = {x: 10, y: 30, z: 50}; - const result = e1.mergeMap(x => e2.map(i => i * x)); + const result = e1.mergeMap(x => e2.map(i => i * +x)); expectObservable(result).toBe(expected, values); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -33,22 +33,22 @@ describe('Observable.prototype.mergeMap', () => { const expected = '----a---(ab)(ab)(ab)c---c---(cd)c---(c|)'; const observableLookup = { a: a, b: b, c: c, d: d }; - const source = e1.mergeMap((value: any) => observableLookup[value]); + const source = e1.mergeMap((value) => observableLookup[value]); expectObservable(source).toBe(expected); expectSubscriptions(e1.subscriptions).toBe(e1subs); }); - it('should map values to constant resolved promises and merge', (done: MochaDone) => { + it('should map values to constant resolved promises and merge', (done) => { const source = Rx.Observable.from([4, 3, 2, 1]); const project = (value: any) => Observable.from(Promise.resolve(42)); - const results = []; + const results: number[] = []; source.mergeMap(project).subscribe( - (x: number) => { + (x) => { results.push(x); }, - (err: any) => { + (err) => { done(new Error('Subscriber error handler not supposed to be called.')); }, () => { @@ -57,17 +57,17 @@ describe('Observable.prototype.mergeMap', () => { }); }); - it('should map values to constant rejected promises and merge', (done: MochaDone) => { + it('should map values to constant rejected promises and merge', (done) => { const source = Rx.Observable.from([4, 3, 2, 1]); - const project = function (value) { + const project = function (value: any) { return Observable.from(Promise.reject(42)); }; source.mergeMap(project).subscribe( - (x: number) => { + (x) => { done(new Error('Subscriber next handler not supposed to be called.')); }, - (err: any) => { + (err) => { expect(err).to.equal(42); done(); }, @@ -76,18 +76,18 @@ describe('Observable.prototype.mergeMap', () => { }); }); - it('should map values to resolved promises and merge', (done: MochaDone) => { + it('should map values to resolved promises and merge', (done) => { const source = Rx.Observable.from([4, 3, 2, 1]); - const project = function (value, index) { + const project = function (value: number, index: number) { return Observable.from(Promise.resolve(value + index)); }; - const results = []; + const results: number[] = []; source.mergeMap(project).subscribe( - (x: number) => { + (x) => { results.push(x); }, - (err: any) => { + (err) => { done(new Error('Subscriber error handler not supposed to be called.')); }, () => { @@ -96,17 +96,17 @@ describe('Observable.prototype.mergeMap', () => { }); }); - it('should map values to rejected promises and merge', (done: MochaDone) => { + it('should map values to rejected promises and merge', (done) => { const source = Rx.Observable.from([4, 3, 2, 1]); - const project = function (value, index) { + const project = function (value: number, index: number) { return Observable.from(Promise.reject('' + value + '-' + index)); }; source.mergeMap(project).subscribe( - (x: string) => { + (x) => { done(new Error('Subscriber next handler not supposed to be called.')); }, - (err: any) => { + (err) => { expect(err).to.equal('4-0'); done(); }, @@ -115,18 +115,18 @@ describe('Observable.prototype.mergeMap', () => { }); }); - it('should mergeMap values to resolved promises with resultSelector', (done: MochaDone) => { + it('should mergeMap values to resolved promises with resultSelector', (done) => { const source = Rx.Observable.from([4, 3, 2, 1]); - const resultSelectorCalledWith = []; - const project = function (value, index) { + const resultSelectorCalledWith: number[][] = []; + const project = function (value: number, index: number) { return Observable.from(Promise.resolve([value, index])); }; - const resultSelector = function (outerVal, innerVal, outerIndex, innerIndex) { + const resultSelector = function (outerVal: number, innerVal: number[], outerIndex: number, innerIndex: number) { resultSelectorCalledWith.push([].slice.call(arguments)); return 8; }; - const results = []; + const results: number[] = []; const expectedCalls = [ [4, [4, 0], 0, 0], [3, [3, 1], 1, 0], @@ -134,10 +134,10 @@ describe('Observable.prototype.mergeMap', () => { [1, [1, 3], 3, 0], ]; source.mergeMap(project, resultSelector).subscribe( - (x: number) => { + (x) => { results.push(x); }, - (err: any) => { + (err) => { done(new Error('Subscriber error handler not supposed to be called.')); }, () => { @@ -147,9 +147,9 @@ describe('Observable.prototype.mergeMap', () => { }); }); - it('should mergeMap values to rejected promises with resultSelector', (done: MochaDone) => { + it('should mergeMap values to rejected promises with resultSelector', (done) => { const source = Rx.Observable.from([4, 3, 2, 1]); - const project = function (value, index) { + const project = function (value: number, index: number) { return Observable.from(Promise.reject('' + value + '-' + index)); }; const resultSelector = () => { @@ -157,10 +157,10 @@ describe('Observable.prototype.mergeMap', () => { }; source.mergeMap(project, resultSelector).subscribe( - (x: any) => { + (x) => { done(new Error('Subscriber next handler not supposed to be called.')); }, - (err: any) => { + (err) => { expect(err).to.equal('4-0'); done(); }, @@ -180,7 +180,7 @@ describe('Observable.prototype.mergeMap', () => { ' ^ !']; const expected = '-----i---j---(ki)(lj)(ki)(lj)(ki)(lj)k---l---|'; - const result = e1.mergeMap((value: any) => inner); + const result = e1.mergeMap((value) => inner); expectObservable(result).toBe(expected, values); expectSubscriptions(inner.subscriptions).toBe(innersubs); @@ -194,7 +194,7 @@ describe('Observable.prototype.mergeMap', () => { const inner = cold('----i---j---k---l---| ', values); const expected = '-----i---j---(ki)(lj)(ki)(lj)(ki)(lj)k---l-------|'; - const result = e1.mergeMap((value: any) => inner); + const result = e1.mergeMap((value) => inner); expectObservable(result).toBe(expected, values); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -208,7 +208,7 @@ describe('Observable.prototype.mergeMap', () => { const inner = cold('----i---j---k---l---| ', values); const expected = '-----i---j---(ki)(lj)(ki)(lj)(ki)(lj)(ki)(lj)k---l---i--'; - const source = e1.mergeMap((value: any) => inner); + const source = e1.mergeMap((value) => inner); expectObservable(source, unsub).toBe(expected, values); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -224,7 +224,7 @@ describe('Observable.prototype.mergeMap', () => { const source = e1 .map(function (x) { return x; }) - .mergeMap((value: any) => inner) + .mergeMap((value) => inner) .map(function (x) { return x; }); expectObservable(source, unsub).toBe(expected, values); @@ -238,7 +238,7 @@ describe('Observable.prototype.mergeMap', () => { const inner = cold('----i---j---k---l-------------------------', values); const expected = '-----i---j---(ki)(lj)(ki)(lj)(ki)(lj)k---l-'; - const result = e1.mergeMap((value: any) => inner); + const result = e1.mergeMap((value) => inner); expectObservable(result).toBe(expected, values); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -251,7 +251,7 @@ describe('Observable.prototype.mergeMap', () => { const inner = cold('----i---j---k---l-------# ', values); const expected = '-----i---j---(ki)(lj)(ki)# '; - const result = e1.mergeMap((value: any) => inner); + const result = e1.mergeMap((value) => inner); expectObservable(result).toBe(expected, values); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -264,7 +264,7 @@ describe('Observable.prototype.mergeMap', () => { const inner = cold('----i---j---k---l---| ', values); const expected = '-----i---j---(ki)(lj)(ki)(lj)(ki)#'; - const result = e1.mergeMap((value: any) => inner); + const result = e1.mergeMap((value) => inner); expectObservable(result).toBe(expected, values); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -277,7 +277,7 @@ describe('Observable.prototype.mergeMap', () => { const inner = cold('----i---j---k---l---# ', values); const expected = '-----i---j---(ki)(lj)# '; - const result = e1.mergeMap((value: any) => inner); + const result = e1.mergeMap((value) => inner); expectObservable(result).toBe(expected, values); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -294,7 +294,7 @@ describe('Observable.prototype.mergeMap', () => { const expected = '-----i---j---k---l-------i---j---k---l-------i---j---k---l---|'; function project() { return inner; } - function resultSelector(oV, iV, oI, iI) { return iV; } + function resultSelector(oV: string, iV: string, oI: number, iI: number) { return iV; } const result = e1.mergeMap(project, resultSelector, 1); expectObservable(result).toBe(expected, values); @@ -313,7 +313,7 @@ describe('Observable.prototype.mergeMap', () => { const expected = '-----i---j---(ki)(lj)k---(li)j---k---l---|'; function project() { return inner; } - function resultSelector(oV, iV, oI, iI) { return iV; } + function resultSelector(oV: string, iV: string, oI: number, iI: number) { return iV; } const result = e1.mergeMap(project, resultSelector, 2); expectObservable(result).toBe(expected, values); @@ -334,8 +334,8 @@ describe('Observable.prototype.mergeMap', () => { const expected = '-----i---j---k---l-------i---j---k---l-------i---j---k---l---|'; const inners = { a: hotA, b: hotB, c: hotC }; - function project(x) { return inners[x]; } - function resultSelector(oV, iV, oI, iI) { return iV; } + function project(x: string) { return inners[x]; } + function resultSelector(oV: string, iV: string, oI: number, iI: number) { return iV; } const result = e1.mergeMap(project, resultSelector, 1); expectObservable(result).toBe(expected, values); @@ -358,8 +358,8 @@ describe('Observable.prototype.mergeMap', () => { const expected = '-----i---j---(ki)(lj)k---(li)j---k---l---|'; const inners = { a: hotA, b: hotB, c: hotC }; - function project(x) { return inners[x]; } - function resultSelector(oV, iV, oI, iI) { return iV; } + function project(x: string) { return inners[x]; } + function resultSelector(oV: string, iV: string, oI: number, iI: number) { return iV; } const result = e1.mergeMap(project, resultSelector, 2); expectObservable(result).toBe(expected, values); @@ -418,7 +418,7 @@ describe('Observable.prototype.mergeMap', () => { const expected = '-----i---j---k---l-------i---j---k---l-------i---j---k---l---|'; const inners = { a: hotA, b: hotB, c: hotC }; - function project(x) { return inners[x]; } + function project(x: string) { return inners[x]; } const result = e1.mergeMap(project, 1); expectObservable(result).toBe(expected, values); @@ -441,7 +441,7 @@ describe('Observable.prototype.mergeMap', () => { const expected = '-----i---j---(ki)(lj)k---(li)j---k---l---|'; const inners = { a: hotA, b: hotB, c: hotC }; - function project(x) { return inners[x]; } + function project(x: string) { return inners[x]; } const result = e1.mergeMap(project, 2); expectObservable(result).toBe(expected, values); @@ -465,7 +465,7 @@ describe('Observable.prototype.mergeMap', () => { const observableLookup = { a: a, b: b, c: c, d: d, e: e, f: f, g: g }; - const result = e1.mergeMap((value: any) => observableLookup[value]); + const result = e1.mergeMap((value) => observableLookup[value]); expectObservable(result).toBe(expected); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -485,7 +485,7 @@ describe('Observable.prototype.mergeMap', () => { const observableLookup = { a: a, b: b, c: c, d: d, e: e, f: f, g: g }; - const result = e1.mergeMap((value: any) => observableLookup[value]); + const result = e1.mergeMap((value) => observableLookup[value]); expectObservable(result).toBe(expected); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -505,7 +505,7 @@ describe('Observable.prototype.mergeMap', () => { const observableLookup = { a: a, b: b, c: c, d: d, e: e, f: f, g: g }; - const result = e1.mergeMap((value: any) => observableLookup[value]); + const result = e1.mergeMap((value) => observableLookup[value]); expectObservable(result).toBe(expected); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -525,7 +525,7 @@ describe('Observable.prototype.mergeMap', () => { const observableLookup = { a: a, b: b, c: c, d: d, e: e, f: f, g: g }; - const result = e1.mergeMap((value: any) => observableLookup[value]); + const result = e1.mergeMap((value) => observableLookup[value]); expectObservable(result).toBe(expected); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -545,7 +545,7 @@ describe('Observable.prototype.mergeMap', () => { const observableLookup = { a: a, b: b, c: c, d: d, e: e, f: f, g: g }; - const result = e1.mergeMap((value: any) => observableLookup[value]); + const result = e1.mergeMap((value) => observableLookup[value]); expectObservable(result).toBe(expected); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -565,7 +565,7 @@ describe('Observable.prototype.mergeMap', () => { const expected = '---2--3--4--5---1--2--3--2--3-- '; const observableLookup = { a: a, b: b, c: c, d: d, e: e, f: f, g: g }; - const source = e1.mergeMap((value: any) => observableLookup[value]); + const source = e1.mergeMap((value) => observableLookup[value]); expectObservable(source, unsub).toBe(expected); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -585,7 +585,7 @@ describe('Observable.prototype.mergeMap', () => { const observableLookup = { a: a, b: b, c: c, d: d, e: e, f: f, g: g }; let invoked = 0; - const source = e1.mergeMap((value: any) => { + const source = e1.mergeMap((value) => { invoked++; if (invoked === 3) { throw 'error'; @@ -597,7 +597,7 @@ describe('Observable.prototype.mergeMap', () => { expectSubscriptions(e1.subscriptions).toBe(e1subs); }); - function arrayRepeat(value, times): any { + function arrayRepeat(value: any, times: number): any { const results = []; for (let i = 0; i < times; i++) { results.push(value); @@ -610,7 +610,7 @@ describe('Observable.prototype.mergeMap', () => { const e1subs = '^ !'; const expected = '(22)--(4444)---(333)----(22)----|'; - const source = e1.mergeMap((value: any) => arrayRepeat(value, value)); + const source = e1.mergeMap((value) => arrayRepeat(value, +value)); expectObservable(source).toBe(expected); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -621,8 +621,8 @@ describe('Observable.prototype.mergeMap', () => { const e1subs = '^ !'; const expected = '(44)--(8888)---(666)----(44)----|'; - const source = e1.mergeMap((value: any) => arrayRepeat(value, value), - (x: string, y: string) => String(parseInt(x) + parseInt(y))); + const source = e1.mergeMap((value) => arrayRepeat(value, +value), + (x, y) => String(parseInt(x) + (+y))); expectObservable(source).toBe(expected); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -633,7 +633,7 @@ describe('Observable.prototype.mergeMap', () => { const e1subs = '^ !'; const expected = '(22)--(4444)---(333)----(22)----#'; - const source = e1.mergeMap((value: any) => arrayRepeat(value, value)); + const source = e1.mergeMap((value) => arrayRepeat(value, +value)); expectObservable(source).toBe(expected); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -644,8 +644,8 @@ describe('Observable.prototype.mergeMap', () => { const e1subs = '^ !'; const expected = '(44)--(8888)---(666)----(44)----#'; - const source = e1.mergeMap((value: any) => arrayRepeat(value, value), - (x: string, y: string) => String(parseInt(x) + parseInt(y))); + const source = e1.mergeMap((value) => arrayRepeat(value, +value), + (x, y) => String(parseInt(x) + (+y))); expectObservable(source).toBe(expected); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -657,7 +657,7 @@ describe('Observable.prototype.mergeMap', () => { const e1subs = '^ ! '; const expected = '(22)--(4444)-- '; - const source = e1.mergeMap((value: any) => arrayRepeat(value, value)); + const source = e1.mergeMap((value) => arrayRepeat(value, +value)); expectObservable(source, unsub).toBe(expected); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -669,8 +669,8 @@ describe('Observable.prototype.mergeMap', () => { const e1subs = '^ ! '; const expected = '(44)--(8888)-- '; - const source = e1.mergeMap((value: any) => arrayRepeat(value, value), - (x: string, y: string) => String(parseInt(x) + parseInt(y))); + const source = e1.mergeMap((value) => arrayRepeat(value, +value), + (x, y) => String(parseInt(x) + (+y))); expectObservable(source, unsub).toBe(expected); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -682,12 +682,12 @@ describe('Observable.prototype.mergeMap', () => { const expected = '(22)--(4444)---# '; let invoked = 0; - const source = e1.mergeMap((value: any) => { + const source = e1.mergeMap((value) => { invoked++; if (invoked === 3) { throw 'error'; } - return arrayRepeat(value, value); + return arrayRepeat(value, +value); }); expectObservable(source).toBe(expected); @@ -699,12 +699,12 @@ describe('Observable.prototype.mergeMap', () => { const e1subs = '^ ! '; const expected = '(44)--(8888)---# '; - const source = e1.mergeMap((value: any) => arrayRepeat(value, value), - (inner: string, outer: string) => { + const source = e1.mergeMap((value) => arrayRepeat(value, +value), + (inner, outer) => { if (outer === '3') { throw 'error'; } - return String(parseInt(outer) + parseInt(inner)); + return String((+outer) + parseInt(inner)); }); expectObservable(source).toBe(expected); @@ -717,14 +717,14 @@ describe('Observable.prototype.mergeMap', () => { const expected = '(44)--(8888)---# '; let invoked = 0; - const source = e1.mergeMap((value: any) => { + const source = e1.mergeMap((value) => { invoked++; if (invoked === 3) { throw 'error'; } - return arrayRepeat(value, value); - }, (inner: string, outer: string) => { - return String(parseInt(outer) + parseInt(inner)); + return arrayRepeat(value, +value); + }, (inner, outer) => { + return String((+outer) + parseInt(inner)); }); expectObservable(source).toBe(expected); @@ -732,12 +732,12 @@ describe('Observable.prototype.mergeMap', () => { }); it('should map and flatten', () => { - const source = Observable.of(1, 2, 3, 4).mergeMap((x: number) => Observable.of(x + '!')); + const source = Observable.of(1, 2, 3, 4).mergeMap((x) => Observable.of(x + '!')); const expected = ['1!', '2!', '3!', '4!']; let completed = false; - source.subscribe((x: string) => { + source.subscribe((x) => { expect(x).to.equal(expected.shift()); }, null, () => { expect(expected.length).to.equal(0); @@ -748,12 +748,12 @@ describe('Observable.prototype.mergeMap', () => { }); it('should map and flatten an Array', () => { - const source = Observable.of(1, 2, 3, 4).mergeMap((x: number): any => [x + '!']); + const source = Observable.of(1, 2, 3, 4).mergeMap((x): any => [x + '!']); const expected = ['1!', '2!', '3!', '4!']; let completed = false; - source.subscribe((x: string) => { + source.subscribe((x) => { expect(x).to.equal(expected.shift()); }, null, () => { expect(expected.length).to.equal(0); diff --git a/spec/operators/mergeMapTo-spec.ts b/spec/operators/mergeMapTo-spec.ts index 2c2737946d..7aaf5cf5c7 100644 --- a/spec/operators/mergeMapTo-spec.ts +++ b/spec/operators/mergeMapTo-spec.ts @@ -42,15 +42,15 @@ describe('Observable.prototype.mergeMapTo', () => { expectSubscriptions(e1.subscriptions).toBe(e1subs); }); - it('should map values to constant resolved promises and merge', (done: MochaDone) => { + it('should map values to constant resolved promises and merge', (done) => { const source = Rx.Observable.from([4, 3, 2, 1]); - const results = []; + const results: number[] = []; source.mergeMapTo(Observable.from(Promise.resolve(42))).subscribe( - (x: any) => { + (x) => { results.push(x); }, - (err: any) => { + (err) => { done(new Error('Subscriber error handler not supposed to be called.')); }, () => { @@ -59,14 +59,14 @@ describe('Observable.prototype.mergeMapTo', () => { }); }); - it('should map values to constant rejected promises and merge', (done: MochaDone) => { + it('should map values to constant rejected promises and merge', (done) => { const source = Rx.Observable.from([4, 3, 2, 1]); source.mergeMapTo(Observable.from(Promise.reject(42))).subscribe( - (x: any) => { + (x) => { done(new Error('Subscriber next handler not supposed to be called.')); }, - (err: any) => { + (err) => { expect(err).to.equal(42); done(); }, @@ -75,16 +75,16 @@ describe('Observable.prototype.mergeMapTo', () => { }); }); - it('should mergeMapTo values to resolved promises with resultSelector', (done: MochaDone) => { + it('should mergeMapTo values to resolved promises with resultSelector', (done) => { const source = Rx.Observable.from([4, 3, 2, 1]); - const resultSelectorCalledWith = []; + const resultSelectorCalledWith: number[][] = []; const inner = Observable.from(Promise.resolve(42)); - const resultSelector = function (outerVal, innerVal, outerIndex, innerIndex) { + const resultSelector = function (outerVal: number, innerVal: number, outerIndex: number, innerIndex: number) { resultSelectorCalledWith.push([].slice.call(arguments)); return 8; }; - const results = []; + const results: number[] = []; const expectedCalls = [ [4, 42, 0, 0], [3, 42, 1, 0], @@ -92,10 +92,10 @@ describe('Observable.prototype.mergeMapTo', () => { [1, 42, 3, 0], ]; source.mergeMapTo(inner, resultSelector).subscribe( - (x: any) => { + (x) => { results.push(x); }, - (err: any) => { + (err) => { done(new Error('Subscriber error handler not supposed to be called.')); }, () => { @@ -105,7 +105,7 @@ describe('Observable.prototype.mergeMapTo', () => { }); }); - it('should mergeMapTo values to rejected promises with resultSelector', (done: MochaDone) => { + it('should mergeMapTo values to rejected promises with resultSelector', (done) => { const source = Rx.Observable.from([4, 3, 2, 1]); const inner = Observable.from(Promise.reject(42)); const resultSelector = () => { @@ -113,10 +113,10 @@ describe('Observable.prototype.mergeMapTo', () => { }; source.mergeMapTo(inner, resultSelector).subscribe( - (x: any) => { + (x) => { done(new Error('Subscriber next handler not supposed to be called.')); }, - (err: any) => { + (err) => { expect(err).to.equal(42); done(); }, @@ -274,7 +274,7 @@ describe('Observable.prototype.mergeMapTo', () => { ' ^ !']; const expected = '-----i---j---k---l-------i---j---k---l-------i---j---k---l---|'; - function resultSelector(oV, iV, oI, iI) { return iV; } + function resultSelector(oV: string, iV: string, oI: number, iI: number) { return iV; } const result = e1.mergeMapTo(inner, resultSelector, 1); expectObservable(result).toBe(expected, values); @@ -292,7 +292,7 @@ describe('Observable.prototype.mergeMapTo', () => { ' ^ !']; const expected = '-----i---j---(ki)(lj)k---(li)j---k---l---|'; - function resultSelector(oV, iV, oI, iI) { return iV; } + function resultSelector(oV: string, iV: string, oI: number, iI: number) { return iV; } const result = e1.mergeMapTo(inner, resultSelector, 2); expectObservable(result).toBe(expected, values); @@ -339,7 +339,7 @@ describe('Observable.prototype.mergeMapTo', () => { const e1subs = '^ !'; const expected = '(0123)(0123)---(0123)---(0123)--|'; - const source = e1.mergeMapTo(['0', '1', '2', '3']); + const source = e1.mergeMapTo(['0', '1', '2', '3']); expectObservable(source).toBe(expected); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -350,8 +350,8 @@ describe('Observable.prototype.mergeMapTo', () => { const e1subs = '^ !'; const expected = '(2345)(4567)---(3456)---(2345)--|'; - const source = e1.mergeMapTo(['0', '1', '2', '3'], - (x: string, y: string) => String(parseInt(x) + parseInt(y))); + const source = e1.mergeMapTo(['0', '1', '2', '3'], + (x, y) => String(parseInt(x) + parseInt(y))); expectObservable(source).toBe(expected); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -362,7 +362,7 @@ describe('Observable.prototype.mergeMapTo', () => { const e1subs = '^ !'; const expected = '(0123)(0123)---(0123)---(0123)--#'; - const source = e1.mergeMapTo(['0', '1', '2', '3']); + const source = e1.mergeMapTo(['0', '1', '2', '3']); expectObservable(source).toBe(expected); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -373,8 +373,8 @@ describe('Observable.prototype.mergeMapTo', () => { const e1subs = '^ !'; const expected = '(2345)(4567)---(3456)---(2345)--#'; - const source = e1.mergeMapTo(['0', '1', '2', '3'], - (x: string, y: string) => String(parseInt(x) + parseInt(y))); + const source = e1.mergeMapTo(['0', '1', '2', '3'], + (x, y) => String(parseInt(x) + parseInt(y))); expectObservable(source).toBe(expected); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -386,7 +386,7 @@ describe('Observable.prototype.mergeMapTo', () => { const unsub = ' !'; const expected = '(0123)(0123)--'; - const source = e1.mergeMapTo(['0', '1', '2', '3']); + const source = e1.mergeMapTo(['0', '1', '2', '3']); expectObservable(source, unsub).toBe(expected); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -398,8 +398,8 @@ describe('Observable.prototype.mergeMapTo', () => { const unsub = ' !'; const expected = '(2345)(4567)--'; - const source = e1.mergeMapTo(['0', '1', '2', '3'], - (x: string, y: string) => String(parseInt(x) + parseInt(y))); + const source = e1.mergeMapTo(['0', '1', '2', '3'], + (x, y) => String(parseInt(x) + parseInt(y))); expectObservable(source, unsub).toBe(expected); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -410,7 +410,7 @@ describe('Observable.prototype.mergeMapTo', () => { const e1subs = '^ !'; const expected = '(2345)(4567)---#'; - const source = e1.mergeMapTo(['0', '1', '2', '3'], (outer: string, inner: string) => { + const source = e1.mergeMapTo(['0', '1', '2', '3'], (outer, inner) => { if (outer === '3') { throw 'error'; } @@ -427,7 +427,7 @@ describe('Observable.prototype.mergeMapTo', () => { const expected = ['!', '!', '!', '!']; let completed = false; - source.subscribe((x: string) => { + source.subscribe((x) => { expect(x).to.equal(expected.shift()); }, null, () => { expect(expected.length).to.equal(0); @@ -438,12 +438,12 @@ describe('Observable.prototype.mergeMapTo', () => { }); it('should map and flatten an Array', () => { - const source = Observable.of(1, 2, 3, 4).mergeMapTo(['!']); + const source = Observable.of(1, 2, 3, 4).mergeMapTo(['!']); const expected = ['!', '!', '!', '!']; let completed = false; - source.subscribe((x: string) => { + source.subscribe((x) => { expect(x).to.equal(expected.shift()); }, null, () => { expect(expected.length).to.equal(0); diff --git a/spec/operators/mergeScan-spec.ts b/spec/operators/mergeScan-spec.ts index e26d651528..b51e016b1f 100644 --- a/spec/operators/mergeScan-spec.ts +++ b/spec/operators/mergeScan-spec.ts @@ -1,5 +1,6 @@ import * as Rx from '../../src/Rx'; import { hot, cold, expectObservable, expectSubscriptions } from '../helpers/marble-testing'; +import { throwError } from '../../src/internal/observable/throwError'; declare const rxTestScheduler: Rx.TestScheduler; const Observable = Rx.Observable; @@ -20,7 +21,7 @@ describe('Observable.prototype.mergeScan', () => { z: ['b', 'c', 'd', 'e', 'f', 'g'] }; - const source = (e1).mergeScan((acc: any, x: string) => Observable.of(acc.concat(x)), []); + const source = e1.mergeScan((acc, x) => Observable.of(acc.concat(x)), []); expectObservable(source).toBe(expected, values); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -37,7 +38,7 @@ describe('Observable.prototype.mergeScan', () => { w: ['b', 'c', 'd'] }; - const source = (e1).mergeScan((acc: any, x: string) => Observable.of(acc.concat(x)), []); + const source = e1.mergeScan((acc, x) => Observable.of(acc.concat(x)), []); expectObservable(source).toBe(expected, values); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -57,7 +58,7 @@ describe('Observable.prototype.mergeScan', () => { z: ['b', 'c', 'd', 'e', 'f', 'g'] }; - const source = (e1).mergeScan((acc: any, x: string) => + const source = e1.mergeScan((acc, x) => Observable.of(acc.concat(x)).delay(20, rxTestScheduler), []); expectObservable(source).toBe(expected, values); @@ -78,7 +79,7 @@ describe('Observable.prototype.mergeScan', () => { z: ['c', 'e', 'g'], }; - const source = (e1).mergeScan((acc: any, x: string) => + const source = e1.mergeScan((acc, x) => Observable.of(acc.concat(x)).delay(50, rxTestScheduler), []); expectObservable(source).toBe(expected, values); @@ -99,7 +100,7 @@ describe('Observable.prototype.mergeScan', () => { z: ['c', 'e', 'g'], }; - const source = (e1).mergeScan((acc: any, x: string) => + const source = e1.mergeScan((acc, x) => Observable.of(acc.concat(x)).delay(50, rxTestScheduler), []); expectObservable(source, e1subs).toBe(expected, values); @@ -121,9 +122,9 @@ describe('Observable.prototype.mergeScan', () => { z: ['c', 'e', 'g'], }; - const source = (e1) - .mergeMap((x: string) => Observable.of(x)) - .mergeScan((acc: any, x: string) => + const source = e1 + .mergeMap((x) => Observable.of(x)) + .mergeScan((acc, x) => Observable.of(acc.concat(x)).delay(50, rxTestScheduler), []) .mergeMap(function (x) { return Observable.of(x); }); @@ -141,7 +142,7 @@ describe('Observable.prototype.mergeScan', () => { v: ['b', 'c'] }; - const source = (e1).mergeScan((acc: any, x: string) => { + const source = e1.mergeScan((acc, x) => { if (x === 'd') { throw 'bad!'; } @@ -157,7 +158,7 @@ describe('Observable.prototype.mergeScan', () => { const e1subs = '^ !'; const expected = '---#'; - const source = (e1).mergeScan((acc: any, x: string) => Observable.throw('bad!'), []); + const source = e1.mergeScan((acc, x) => throwError('bad!'), []); expectObservable(source).toBe(expected, undefined, 'bad!'); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -168,9 +169,9 @@ describe('Observable.prototype.mergeScan', () => { const e1subs = '^ !'; const expected = '---------------------(x|)'; - const values = { x: [] }; + const values = { x: [] }; - const source = (e1).mergeScan((acc: any, x: string) => Observable.empty(), []); + const source = e1.mergeScan((acc, x) => Observable.empty(), []); expectObservable(source).toBe(expected, values); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -181,9 +182,9 @@ describe('Observable.prototype.mergeScan', () => { const e1subs = '^ '; const expected = '----------------------'; - const values = { x: [] }; + const values = { x: [] }; - const source = (e1).mergeScan((acc: any, x: string) => Observable.never(), []); + const source = e1.mergeScan((acc, x) => Observable.never(), []); expectObservable(source).toBe(expected, values); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -195,10 +196,10 @@ describe('Observable.prototype.mergeScan', () => { const expected = '(u|)'; const values = { - u: [] + u: [] }; - const source = (e1).mergeScan((acc: any, x: string) => Observable.of(acc.concat(x)), []); + const source = e1.mergeScan((acc, x) => Observable.of(acc.concat(x)), []); expectObservable(source).toBe(expected, values); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -209,7 +210,7 @@ describe('Observable.prototype.mergeScan', () => { const e1subs = '^'; const expected = '-'; - const source = (e1).mergeScan((acc: any, x: string) => Observable.of(acc.concat(x)), []); + const source = e1.mergeScan((acc, x) => Observable.of(acc.concat(x)), []); expectObservable(source).toBe(expected); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -220,7 +221,7 @@ describe('Observable.prototype.mergeScan', () => { const e1subs = '(^!)'; const expected = '#'; - const source = (e1).mergeScan((acc: any, x: string) => Observable.of(acc.concat(x)), []); + const source = e1.mergeScan((acc, x) => Observable.of(acc.concat(x)), []); expectObservable(source).toBe(expected); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -239,7 +240,7 @@ describe('Observable.prototype.mergeScan', () => { z: ['b', 'c', 'd', 'e', 'f', 'g'] }; - const source = (e1).mergeScan((acc: any, x: string) => Observable.of(acc.concat(x)), []); + const source = e1.mergeScan((acc, x) => Observable.of(acc.concat(x)), []); expectObservable(source, sub).toBe(expected, values); expectSubscriptions(e1.subscriptions).toBe(sub); @@ -262,7 +263,7 @@ describe('Observable.prototype.mergeScan', () => { const expected = '--x-d--e--f--f-g--h--i--i-j--k--l--|'; let index = 0; - const source = (e1).mergeScan((acc: any, x: string) => { + const source = e1.mergeScan((acc, x) => { const value = inner[index++]; return value.startWith(acc); }, 'x', 1); @@ -280,7 +281,7 @@ describe('Observable.prototype.mergeScan', () => { const e1subs = '^ !'; const expected = '---------------------(x|)'; - const source = (e1).mergeScan((acc: any, x: string) => Observable.empty(), ['1']); + const source = e1.mergeScan((acc, x) => Observable.empty(), ['1']); expectObservable(source).toBe(expected, {x: ['1']}); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -291,7 +292,7 @@ describe('Observable.prototype.mergeScan', () => { const e1subs = '^ !'; const expected = '-----------------------(x|)'; - const source = (e1).mergeScan((acc: any, x: string) => + const source = e1.mergeScan((acc, x) => Observable.empty().delay(50, rxTestScheduler), ['1']); expectObservable(source).toBe(expected, {x: ['1']}); @@ -315,7 +316,7 @@ describe('Observable.prototype.mergeScan', () => { const expected = '---x-e--f--f--i----i-l------|'; let index = 0; - const source = (e1).mergeScan((acc: any, x: string) => { + const source = e1.mergeScan((acc, x) => { const value = inner[index++]; return value.startWith(acc); }, 'x', 1); @@ -345,7 +346,7 @@ describe('Observable.prototype.mergeScan', () => { const expected = '----x--d-d-eg--fh--hi-j---k---l---|'; let index = 0; - const source = (e1).mergeScan((acc: any, x: string) => { + const source = e1.mergeScan((acc, x) => { const value = inner[index++]; return value.startWith(acc); }, 'x', 2); @@ -375,7 +376,7 @@ describe('Observable.prototype.mergeScan', () => { const expected = '---x-e-efh-h-ki------l------|'; let index = 0; - const source = (e1).mergeScan((acc: any, x: string) => { + const source = e1.mergeScan((acc, x) => { const value = inner[index++]; return value.startWith(acc); }, 'x', 2); diff --git a/spec/operators/switch-spec.ts b/spec/operators/switch-spec.ts index bf250aefcb..69c00df844 100644 --- a/spec/operators/switch-spec.ts +++ b/spec/operators/switch-spec.ts @@ -3,7 +3,7 @@ import * as Rx from '../../src/Rx'; import { hot, cold, expectObservable, expectSubscriptions } from '../helpers/marble-testing'; declare function asDiagram(arg: string): Function; - +declare const type: Function; const Observable = Rx.Observable; const queueScheduler = Rx.Scheduler.queue; @@ -18,23 +18,23 @@ describe('Observable.prototype.switch', () => { expectObservable(e1.switch()).toBe(expected); }); - it('should switch to each immediately-scheduled inner Observable', (done: MochaDone) => { + it('should switch to each immediately-scheduled inner Observable', (done) => { const a = Observable.of(1, 2, 3, queueScheduler); const b = Observable.of(4, 5, 6, queueScheduler); const r = [1, 4, 5, 6]; let i = 0; - Observable.of>(a, b, queueScheduler) + Observable.of(a, b, queueScheduler) .switch() - .subscribe((x: number) => { + .subscribe((x) => { expect(x).to.equal(r[i++]); }, null, done); }); it('should unsub inner observables', () => { - const unsubbed = []; + const unsubbed: string[] = []; - Observable.of('a', 'b').map((x: string) => - Observable.create((subscriber: Rx.Subscriber) => { + Observable.of('a', 'b').map((x) => + new Observable((subscriber) => { subscriber.complete(); return () => { unsubbed.push(x); @@ -46,12 +46,12 @@ describe('Observable.prototype.switch', () => { expect(unsubbed).to.deep.equal(['a', 'b']); }); - it('should switch to each inner Observable', (done: MochaDone) => { + it('should switch to each inner Observable', (done) => { const a = Observable.of(1, 2, 3); const b = Observable.of(4, 5, 6); const r = [1, 2, 3, 4, 5, 6]; let i = 0; - Observable.of(a, b).switch().subscribe((x: number) => { + Observable.of(a, b).switch().subscribe((x) => { expect(x).to.equal(r[i++]); }, null, done); }); @@ -90,10 +90,10 @@ describe('Observable.prototype.switch', () => { const expected = '--------a---b---- '; const unsub = ' ! '; - const result = (e1) - .mergeMap((x: string) => Observable.of(x)) + const result = e1 + .mergeMap((x) => Observable.of(x)) .switch() - .mergeMap((x: any) => Observable.of(x)); + .mergeMap((x) => Observable.of(x)); expectObservable(result, unsub).toBe(expected); expectSubscriptions(x.subscriptions).toBe(xsubs); @@ -128,7 +128,7 @@ describe('Observable.prototype.switch', () => { const x = cold( '--a---# '); const xsubs = ' ^ ! '; const y = cold( '---d--e---f---|'); - const ysubs = []; + const ysubs: string[] = []; const e1 = hot( '------x-------y------| ', { x: x, y: y }); const expected = '--------a---# '; expectObservable(e1.switch()).toBe(expected); @@ -178,12 +178,12 @@ describe('Observable.prototype.switch', () => { expectSubscriptions(e1.subscriptions).toBe(e1subs); }); - it('should handle an observable of promises', (done: MochaDone) => { + it('should handle an observable of promises', (done) => { const expected = [3]; - (Observable.of(Promise.resolve(1), Promise.resolve(2), Promise.resolve(3))) + Observable.of(Promise.resolve(1), Promise.resolve(2), Promise.resolve(3)) .switch() - .subscribe((x: number) => { + .subscribe((x) => { expect(x).to.equal(expected.shift()); }, null, () => { expect(expected.length).to.equal(0); @@ -191,12 +191,12 @@ describe('Observable.prototype.switch', () => { }); }); - it('should handle an observable of promises, where last rejects', (done: MochaDone) => { - Observable.of(Promise.resolve(1), Promise.resolve(2), Promise.reject(3)) + it('should handle an observable of promises, where last rejects', (done) => { + Observable.of(Promise.resolve(1), Promise.resolve(2), Promise.reject(3)) .switch() .subscribe(() => { done(new Error('should not be called')); - }, (err: any) => { + }, (err) => { expect(err).to.equal(3); done(); }, () => { @@ -208,9 +208,9 @@ describe('Observable.prototype.switch', () => { const expected = [1, 2, 3, 4]; let completed = false; - Observable.of(Observable.never(), Observable.never(), [1, 2, 3, 4]) + Observable.of(Observable.never(), Observable.never(), [1, 2, 3, 4]) .switch() - .subscribe((x: number) => { + .subscribe((x) => { expect(x).to.equal(expected.shift()); }, null, () => { completed = true; @@ -224,11 +224,11 @@ describe('Observable.prototype.switch', () => { let iStream: Rx.Subject; const oStreamControl = new Rx.Subject(); const oStream = oStreamControl.map(() => { - return (iStream = new Rx.Subject()); + return (iStream = new Rx.Subject()); }); const switcher = oStream.switch(); - const result = []; - let sub = switcher.subscribe((x: number) => result.push(x)); + const result: number[] = []; + let sub = switcher.subscribe((x) => result.push(x)); [0, 1, 2, 3, 4].forEach((n) => { oStreamControl.next(n); // creates inner @@ -244,11 +244,11 @@ describe('Observable.prototype.switch', () => { it('should not leak if we switch before child completes (prevent memory leaks #2355)', () => { const oStreamControl = new Rx.Subject(); const oStream = oStreamControl.map(() => { - return (new Rx.Subject()); + return (new Rx.Subject()); }); const switcher = oStream.switch(); - const result = []; - let sub = switcher.subscribe((x: number) => result.push(x)); + const result: number[] = []; + let sub = switcher.subscribe((x) => result.push(x)); [0, 1, 2, 3, 4].forEach((n) => { oStreamControl.next(n); // creates inner @@ -259,4 +259,54 @@ describe('Observable.prototype.switch', () => { ).to.equal(2); sub.unsubscribe(); }); + + type(() => { + /* tslint:disable:no-unused-variable */ + const source1 = Rx.Observable.of(1, 2, 3); + const source2 = [1, 2, 3]; + const source3 = new Promise(d => d(1)); + + let result: Rx.Observable = Rx.Observable + .of(source1, source2, source3) + .pipe(Rx.operators.switchAll()); + /* tslint:enable:no-unused-variable */ + }); + + type(() => { + /* tslint:disable:no-unused-variable */ + const source1 = Rx.Observable.of(1, 2, 3); + const source2 = [1, 2, 3]; + const source3 = new Promise(d => d(1)); + + let result: Rx.Observable = Rx.Observable + .of(source1, source2, source3) + .switch(); + /* tslint:enable:no-unused-variable */ + }); + + type(() => { + // coerce type to a specific type + /* tslint:disable:no-unused-variable */ + const source1 = Rx.Observable.of(1, 2, 3); + const source2 = [1, 2, 3]; + const source3 = new Promise(d => d(1)); + + let result: Rx.Observable = Rx.Observable + .of(source1, source2, source3) + .pipe(Rx.operators.switchAll()); + /* tslint:enable:no-unused-variable */ + }); + + type(() => { + // coerce type to a specific type + /* tslint:disable:no-unused-variable */ + const source1 = Rx.Observable.of(1, 2, 3); + const source2 = [1, 2, 3]; + const source3 = new Promise(d => d(1)); + + let result: Rx.Observable = Rx.Observable + .of(source1, source2, source3) + .switch(); + /* tslint:enable:no-unused-variable */ + }); }); diff --git a/spec/operators/switchMap-spec.ts b/spec/operators/switchMap-spec.ts index 8afab6805e..4b80c1e1b9 100644 --- a/spec/operators/switchMap-spec.ts +++ b/spec/operators/switchMap-spec.ts @@ -16,26 +16,26 @@ describe('Observable.prototype.switchMap', () => { const expected = '--x-x-x-y-yz-z-z---|'; const values = {x: 10, y: 30, z: 50}; - const result = e1.switchMap(x => e2.map(i => i * x)); + const result = e1.switchMap(x => e2.map(i => i * +x)); expectObservable(result).toBe(expected, values); expectSubscriptions(e1.subscriptions).toBe(e1subs); }); - it('should switch with a selector function', (done: MochaDone) => { + it('should switch with a selector function', (done) => { const a = Observable.of(1, 2, 3); const expected = ['a1', 'b1', 'c1', 'a2', 'b2', 'c2', 'a3', 'b3', 'c3']; - a.switchMap((x: number) => Observable.of('a' + x, 'b' + x, 'c' + x)) - .subscribe((x: string) => { + a.switchMap((x) => Observable.of('a' + x, 'b' + x, 'c' + x)) + .subscribe((x) => { expect(x).to.equal(expected.shift()); }, null, done); }); it('should unsub inner observables', () => { - const unsubbed = []; + const unsubbed: string[] = []; - Observable.of('a', 'b').switchMap((x: string) => - Observable.create((subscriber: Rx.Subscriber) => { + Observable.of('a', 'b').switchMap((x) => + new Observable((subscriber) => { subscriber.complete(); return () => { unsubbed.push(x); @@ -56,7 +56,7 @@ describe('Observable.prototype.switchMap', () => { const observableLookup = { x: x, y: y }; - const result = e1.switchMap((value: string) => observableLookup[value]); + const result = e1.switchMap((value) => observableLookup[value]); expectObservable(result).toBe(expected); expectSubscriptions(x.subscriptions).toBe(xsubs); @@ -68,11 +68,11 @@ describe('Observable.prototype.switchMap', () => { const e1 = hot('-------x-----y---|'); const e1subs = '^ ! '; const expected = '-------# '; - function project() { + function project(): any[] { throw 'error'; } - expectObservable(e1.switchMap(project)).toBe(expected); + expectObservable(e1.switchMap(project)).toBe(expected); expectSubscriptions(e1.subscriptions).toBe(e1subs); }); @@ -87,7 +87,7 @@ describe('Observable.prototype.switchMap', () => { throw 'error'; } - const result = e1.switchMap((value: string) => x, selector); + const result = e1.switchMap((value) => x, selector); expectObservable(result).toBe(expected); expectSubscriptions(x.subscriptions).toBe(xsubs); @@ -106,7 +106,7 @@ describe('Observable.prototype.switchMap', () => { const observableLookup = { x: x, y: y }; - const result = e1.switchMap((value: string) => observableLookup[value]); + const result = e1.switchMap((value) => observableLookup[value]); expectObservable(result, unsub).toBe(expected); expectSubscriptions(x.subscriptions).toBe(xsubs); @@ -127,9 +127,9 @@ describe('Observable.prototype.switchMap', () => { const observableLookup = { x: x, y: y }; const result = e1 - .mergeMap((x: string) => Observable.of(x)) - .switchMap((value: string) => observableLookup[value]) - .mergeMap((x: string) => Observable.of(x)); + .mergeMap((x) => Observable.of(x)) + .switchMap((value) => observableLookup[value]) + .mergeMap((x) => Observable.of(x)); expectObservable(result, unsub).toBe(expected); expectSubscriptions(x.subscriptions).toBe(xsubs); @@ -148,7 +148,7 @@ describe('Observable.prototype.switchMap', () => { const observableLookup = { x: x, y: y }; - const result = e1.switchMap((value: string) => observableLookup[value]); + const result = e1.switchMap((value) => observableLookup[value]); expectObservable(result).toBe(expected); expectSubscriptions(x.subscriptions).toBe(xsubs); @@ -167,7 +167,7 @@ describe('Observable.prototype.switchMap', () => { const observableLookup = { x: x, y: y }; - const result = e1.switchMap((value: string) => observableLookup[value]); + const result = e1.switchMap((value) => observableLookup[value]); expectObservable(result).toBe(expected); expectSubscriptions(x.subscriptions).toBe(xsubs); @@ -179,14 +179,14 @@ describe('Observable.prototype.switchMap', () => { const x = cold( '--a--b--#--d--e--| '); const xsubs = ' ^ ! '; const y = cold( '---f---g---h---i--'); - const ysubs = []; + const ysubs: string[] = []; const e1 = hot('---------x---------y---------| '); const e1subs = '^ ! '; const expected = '-----------a--b--# '; const observableLookup = { x: x, y: y }; - const result = e1.switchMap((value: string) => observableLookup[value]); + const result = e1.switchMap((value) => observableLookup[value]); expectObservable(result).toBe(expected); expectSubscriptions(x.subscriptions).toBe(xsubs); @@ -205,7 +205,7 @@ describe('Observable.prototype.switchMap', () => { const observableLookup = { x: x, y: y }; - const result = e1.switchMap((value: string) => observableLookup[value]); + const result = e1.switchMap((value) => observableLookup[value]); expectObservable(result).toBe(expected); expectSubscriptions(x.subscriptions).toBe(xsubs); @@ -224,7 +224,7 @@ describe('Observable.prototype.switchMap', () => { const observableLookup = { x: x, y: y }; - const result = e1.switchMap((value: string) => observableLookup[value]); + const result = e1.switchMap((value) => observableLookup[value]); expectObservable(result).toBe(expected); expectSubscriptions(x.subscriptions).toBe(xsubs); @@ -243,7 +243,7 @@ describe('Observable.prototype.switchMap', () => { const observableLookup = { x: x, y: y }; - const result = e1.switchMap((value: string) => observableLookup[value]); + const result = e1.switchMap((value) => observableLookup[value]); expectObservable(result).toBe(expected); expectSubscriptions(x.subscriptions).toBe(xsubs); @@ -262,7 +262,7 @@ describe('Observable.prototype.switchMap', () => { const observableLookup = { x: x, y: y }; - const result = e1.switchMap((value: string) => observableLookup[value]); + const result = e1.switchMap((value) => observableLookup[value]); expectObservable(result).toBe(expected); expectSubscriptions(x.subscriptions).toBe(xsubs); @@ -281,7 +281,7 @@ describe('Observable.prototype.switchMap', () => { const observableLookup = { x: x, y: y }; - const result = e1.switchMap((value: string) => observableLookup[value]); + const result = e1.switchMap((value) => observableLookup[value]); expectObservable(result).toBe(expected, undefined, 'sad'); expectSubscriptions(x.subscriptions).toBe(xsubs); @@ -300,7 +300,7 @@ describe('Observable.prototype.switchMap', () => { const observableLookup = { x: x, y: y }; - const result = e1.switchMap((value: string) => observableLookup[value]); + const result = e1.switchMap((value) => observableLookup[value]); expectObservable(result).toBe(expected, undefined, 'sad'); expectSubscriptions(x.subscriptions).toBe(xsubs); @@ -313,7 +313,7 @@ describe('Observable.prototype.switchMap', () => { const e1subs = '(^!)'; const expected = '|'; - const result = e1.switchMap((value: any) => Observable.of(value)); + const result = e1.switchMap((value) => Observable.of(value)); expectObservable(result).toBe(expected); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -324,7 +324,7 @@ describe('Observable.prototype.switchMap', () => { const e1subs = '^'; const expected = '-'; - const result = e1.switchMap((value: any) => Observable.of(value)); + const result = e1.switchMap((value) => Observable.of(value)); expectObservable(result).toBe(expected); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -335,7 +335,7 @@ describe('Observable.prototype.switchMap', () => { const e1subs = '(^!)'; const expected = '#'; - const result = e1.switchMap((value: any) => Observable.of(value)); + const result = e1.switchMap((value) => Observable.of(value)); expectObservable(result).toBe(expected); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -350,7 +350,7 @@ describe('Observable.prototype.switchMap', () => { const observableLookup = { x: x }; - const result = e1.switchMap((value: string) => observableLookup[value]); + const result = e1.switchMap((value) => observableLookup[value]); expectObservable(result).toBe(expected); expectSubscriptions(x.subscriptions).toBe(xsubs); @@ -378,7 +378,7 @@ describe('Observable.prototype.switchMap', () => { i: ['y', 'i', 1, 3] }; - const result = e1.switchMap((value: string) => observableLookup[value], + const result = e1.switchMap((value) => observableLookup[value], (innerValue, outerValue, innerIndex, outerIndex) => [innerValue, outerValue, innerIndex, outerIndex]); expectObservable(result).toBe(expected, expectedValues); diff --git a/spec/operators/switchMapTo-spec.ts b/spec/operators/switchMapTo-spec.ts index c0707a353d..ba54989151 100644 --- a/spec/operators/switchMapTo-spec.ts +++ b/spec/operators/switchMapTo-spec.ts @@ -22,10 +22,10 @@ describe('Observable.prototype.switchMapTo', () => { expectSubscriptions(e1.subscriptions).toBe(e1subs); }); - it('should switch a synchronous many outer to a synchronous many inner', (done: MochaDone) => { + it('should switch a synchronous many outer to a synchronous many inner', (done) => { const a = Observable.of(1, 2, 3); const expected = ['a', 'b', 'c', 'a', 'b', 'c', 'a', 'b', 'c']; - a.switchMapTo(Observable.of('a', 'b', 'c')).subscribe((x: string) => { + a.switchMapTo(Observable.of('a', 'b', 'c')).subscribe((x) => { expect(x).to.equal(expected.shift()); }, null, done); }); @@ -34,7 +34,7 @@ describe('Observable.prototype.switchMapTo', () => { let unsubbed = 0; Observable.of('a', 'b').switchMapTo( - Observable.create((subscriber: Rx.Subscriber) => { + new Observable((subscriber) => { subscriber.complete(); return () => { unsubbed++; @@ -97,9 +97,9 @@ describe('Observable.prototype.switchMapTo', () => { const unsub = ' ! '; const result = e1 - .mergeMap((x: string) => Observable.of(x)) + .mergeMap((x) => Observable.of(x)) .switchMapTo(x) - .mergeMap((x: string) => Observable.of(x)); + .mergeMap((x) => Observable.of(x)); expectObservable(result, unsub).toBe(expected); expectSubscriptions(x.subscriptions).toBe(xsubs); diff --git a/spec/operators/zip-spec.ts b/spec/operators/zip-spec.ts index 466e86fa84..fe690d2e94 100644 --- a/spec/operators/zip-spec.ts +++ b/spec/operators/zip-spec.ts @@ -2,9 +2,8 @@ import { expect } from 'chai'; import * as Rx from '../../src/Rx'; import { hot, cold, expectObservable, expectSubscriptions } from '../helpers/marble-testing'; -declare const type; +declare const type: Function; -declare const Symbol: any; const Observable = Rx.Observable; const queueScheduler = Rx.Scheduler.queue; @@ -23,13 +22,13 @@ describe('Observable.prototype.zip', () => { expectSubscriptions(b.subscriptions).toBe(bsubs); }); - it('should zip the provided observables', (done: MochaDone) => { + it('should zip the provided observables', (done) => { const expected = ['a1', 'b2', 'c3']; let i = 0; Observable.from(['a', 'b', 'c']).zip( Observable.from([1, 2, 3]), - (a: string, b: number): string => a + b + (a, b): string => a + b ) .subscribe(function (x) { expect(x).to.equal(expected[i++]); @@ -124,7 +123,7 @@ describe('Observable.prototype.zip', () => { it('should work with never observable and empty iterable', () => { const a = cold( '-'); const asubs = '^'; - const b = []; + const b: string[] = []; const expected = '-'; expectObservable(a.zip(b)).toBe(expected); @@ -134,7 +133,7 @@ describe('Observable.prototype.zip', () => { it('should work with empty observable and empty iterable', () => { const a = cold('|'); const asubs = '(^!)'; - const b = []; + const b: string[] = []; const expected = '|'; expectObservable(a.zip(b)).toBe(expected); @@ -154,7 +153,7 @@ describe('Observable.prototype.zip', () => { it('should work with non-empty observable and empty iterable', () => { const a = hot('---^----a--|'); const asubs = '^ !'; - const b = []; + const b: string[] = []; const expected = '--------|'; expectObservable(a.zip(b)).toBe(expected); @@ -184,7 +183,7 @@ describe('Observable.prototype.zip', () => { it('should work with non-empty observable and empty iterable', () => { const a = hot('---^----#'); const asubs = '^ !'; - const b = []; + const b: string[] = []; const expected = '-----#'; expectObservable(a.zip(b)).toBe(expected); @@ -218,7 +217,7 @@ describe('Observable.prototype.zip', () => { const b = [4, 5, 6]; const expected = '---x--#'; - const selector = function (x, y) { + const selector = function (x: string, y: number) { if (y === 5) { throw new Error('too bad'); } else { @@ -335,7 +334,7 @@ describe('Observable.prototype.zip', () => { const bsubs = '^ ! '; const expected = '---x----# '; - const selector = function (x, y) { + const selector = function (x: string, y: string) { if (y === '5') { throw new Error('too bad'); } else { @@ -564,7 +563,7 @@ describe('Observable.prototype.zip', () => { expectSubscriptions(b.subscriptions).toBe(bsubs); }); - it('should combine an immediately-scheduled source with an immediately-scheduled second', (done: MochaDone) => { + it('should combine an immediately-scheduled source with an immediately-scheduled second', (done) => { const a = Observable.of(1, 2, 3, queueScheduler); const b = Observable.of(4, 5, 6, 7, 8, queueScheduler); const r = [[1, 4], [2, 5], [3, 6]]; @@ -584,9 +583,9 @@ describe('Observable.prototype.zip', () => { const expected = '---x---y--'; const r = a - .mergeMap((x: string) => Observable.of(x)) + .mergeMap((x) => Observable.of(x)) .zip(b) - .mergeMap((x: Array) => Observable.of(x)); + .mergeMap((x) => Observable.of(x)); expectObservable(r, unsub).toBe(expected, { x: ['1', '4'], y: ['2', '5']}); expectSubscriptions(a.subscriptions).toBe(asubs); @@ -613,7 +612,7 @@ describe('Observable.prototype.zip', () => { /* tslint:disable:no-unused-variable */ let o: Rx.Observable; let z: Rx.Observable[]; - let a: Rx.Observable = o.zip(z, (...r) => r.map(v => v.toString())); + let a: Rx.Observable = o.zip(z, (...r: any[]) => r.map(v => v.toString())); /* tslint:enable:no-unused-variable */ }); }); diff --git a/spec/operators/zipAll-spec.ts b/spec/operators/zipAll-spec.ts index a7d1ab4eeb..8590837274 100644 --- a/spec/operators/zipAll-spec.ts +++ b/spec/operators/zipAll-spec.ts @@ -3,8 +3,7 @@ import * as Rx from '../../src/Rx'; import { hot, cold, expectObservable, expectSubscriptions } from '../helpers/marble-testing'; declare function asDiagram(arg: string): Function; - -declare const Symbol: any; +declare const type: Function; const Observable = Rx.Observable; const queueScheduler = Rx.Scheduler.queue; @@ -16,7 +15,7 @@ describe('Observable.prototype.zipAll', () => { const outer = hot('-x----y--------| ', { x: x, y: y }); const expected = '-----------------A----B-|'; - const result = outer.zipAll((a: string, b: string) => String(a) + String(b)); + const result = outer.zipAll((a, b) => String(a) + String(b)); expectObservable(result).toBe(expected, { A: 'a1', B: 'b2' }); }); @@ -29,20 +28,20 @@ describe('Observable.prototype.zipAll', () => { const expected = '---x---y---z'; const values = { x: ['1', '4'], y: ['2', '5'], z: ['3', '6'] }; - expectObservable(Observable.of(a, b).zipAll()).toBe(expected, values); + expectObservable(Observable.of(a, b).zipAll()).toBe(expected, values); expectSubscriptions(a.subscriptions).toBe(asubs); expectSubscriptions(b.subscriptions).toBe(bsubs); }); - it('should take all observables from the source and zip them', (done: MochaDone) => { + it('should take all observables from the source and zip them', (done) => { const expected = ['a1', 'b2', 'c3']; let i = 0; - Observable.of( - Observable.of('a', 'b', 'c'), - Observable.of(1, 2, 3) + Observable.of( + Observable.of('a', 'b', 'c'), + Observable.of(1, 2, 3) ) - .zipAll((a: any, b: any) => a + b) - .subscribe((x: any) => { + .zipAll((a, b) => a + b) + .subscribe((x) => { expect(x).to.equal(expected[i++]); }, null, done); }); @@ -61,7 +60,7 @@ describe('Observable.prototype.zipAll', () => { z: ['c', 'f', 'j'] }; - expectObservable(Observable.of(e1, e2, e3).zipAll()).toBe(expected, values); + expectObservable(Observable.of(e1, e2, e3).zipAll()).toBe(expected, values); expectSubscriptions(e1.subscriptions).toBe(e1subs); expectSubscriptions(e2.subscriptions).toBe(e2subs); expectSubscriptions(e3.subscriptions).toBe(e3subs); @@ -82,7 +81,7 @@ describe('Observable.prototype.zipAll', () => { z: ['c', 'f', 'j'] }; - expectObservable(Observable.of(e1, e2, e3).zipAll()).toBe(expected, values); + expectObservable(Observable.of(e1, e2, e3).zipAll()).toBe(expected, values); expectSubscriptions(e1.subscriptions).toBe(e1subs); expectSubscriptions(e2.subscriptions).toBe(e2subs); expectSubscriptions(e3.subscriptions).toBe(e3subs); @@ -92,11 +91,13 @@ describe('Observable.prototype.zipAll', () => { it('should zip them with values', () => { const myIterator = { count: 0, - next: function () { + next() { return { value: this.count++, done: false }; + }, + [Symbol.iterator]() { + return this; } }; - myIterator[Symbol.iterator] = function () { return this; }; const e1 = hot('---a---b---c---d---|'); const e1subs = '^ !'; @@ -109,7 +110,7 @@ describe('Observable.prototype.zipAll', () => { z: ['d', 3] }; - expectObservable(Observable.of(e1, myIterator).zipAll()).toBe(expected, values); + expectObservable(Observable.of(e1, myIterator).zipAll()).toBe(expected, values); expectSubscriptions(e1.subscriptions).toBe(e1subs); }); @@ -117,14 +118,16 @@ describe('Observable.prototype.zipAll', () => { let nextCalled = 0; const myIterator = { count: 0, - next: function () { + next() { nextCalled++; return { value: this.count++, done: false }; + }, + [Symbol.iterator]() { + return this; } }; - myIterator[Symbol.iterator] = function () { return this; }; - Observable.of(Observable.of(1, 2, 3), myIterator).zipAll() + Observable.of(Observable.of(1, 2, 3), myIterator).zipAll() .subscribe(); // since zip will call `next()` in advance, total calls when @@ -135,20 +138,20 @@ describe('Observable.prototype.zipAll', () => { it('should work with never observable and empty iterable', () => { const a = cold( '-'); const asubs = '^'; - const b = []; + const b: string[] = []; const expected = '-'; - expectObservable(Observable.of(a, b).zipAll()).toBe(expected); + expectObservable(Observable.of(a, b).zipAll()).toBe(expected); expectSubscriptions(a.subscriptions).toBe(asubs); }); it('should work with empty observable and empty iterable', () => { const a = cold('|'); const asubs = '(^!)'; - const b = []; + const b: string[] = []; const expected = '|'; - expectObservable(Observable.of(a, b).zipAll()).toBe(expected); + expectObservable(Observable.of(a, b).zipAll()).toBe(expected); expectSubscriptions(a.subscriptions).toBe(asubs); }); @@ -158,17 +161,17 @@ describe('Observable.prototype.zipAll', () => { const b = [1]; const expected = '|'; - expectObservable(Observable.of(a, b).zipAll()).toBe(expected); + expectObservable(Observable.of(a, b).zipAll()).toBe(expected); expectSubscriptions(a.subscriptions).toBe(asubs); }); it('should work with non-empty observable and empty iterable', () => { const a = hot('---^----a--|'); const asubs = '^ !'; - const b = []; + const b: string[] = []; const expected = '--------|'; - expectObservable(Observable.of(a, b).zipAll()).toBe(expected); + expectObservable(Observable.of(a, b).zipAll()).toBe(expected); expectSubscriptions(a.subscriptions).toBe(asubs); }); @@ -178,7 +181,7 @@ describe('Observable.prototype.zipAll', () => { const b = [1]; const expected = '-'; - expectObservable(Observable.of(a, b).zipAll()).toBe(expected); + expectObservable(Observable.of(a, b).zipAll()).toBe(expected); expectSubscriptions(a.subscriptions).toBe(asubs); }); @@ -188,17 +191,17 @@ describe('Observable.prototype.zipAll', () => { const b = [2]; const expected = '-----(x|)'; - expectObservable(Observable.of(a, b).zipAll()).toBe(expected, { x: ['1', 2] }); + expectObservable(Observable.of(a, b).zipAll()).toBe(expected, { x: ['1', 2] }); expectSubscriptions(a.subscriptions).toBe(asubs); }); it('should work with non-empty observable and empty iterable', () => { const a = hot('---^----#'); const asubs = '^ !'; - const b = []; + const b: string[] = []; const expected = '-----#'; - expectObservable(Observable.of(a, b).zipAll()).toBe(expected); + expectObservable(Observable.of(a, b).zipAll()).toBe(expected); expectSubscriptions(a.subscriptions).toBe(asubs); }); @@ -208,7 +211,7 @@ describe('Observable.prototype.zipAll', () => { const b = [1]; const expected = '-----#'; - expectObservable(Observable.of(a, b).zipAll()).toBe(expected); + expectObservable(Observable.of(a, b).zipAll()).toBe(expected); expectSubscriptions(a.subscriptions).toBe(asubs); }); @@ -218,7 +221,7 @@ describe('Observable.prototype.zipAll', () => { const b = [4, 5, 6]; const expected = '---x--y--(z|)'; - expectObservable(Observable.of(a, b).zipAll()).toBe(expected, + expectObservable(Observable.of(a, b).zipAll()).toBe(expected, { x: ['1', 4], y: ['2', 5], z: ['3', 6] }); expectSubscriptions(a.subscriptions).toBe(asubs); }); @@ -229,13 +232,13 @@ describe('Observable.prototype.zipAll', () => { const b = [4, 5, 6]; const expected = '---x--#'; - const selector = function (x, y) { + const selector = function (x: number, y: number) { if (y === 5) { throw new Error('too bad'); } else { return x + y; }}; - expectObservable(Observable.of(a, b).zipAll(selector)).toBe(expected, + expectObservable(Observable.of(a, b).zipAll(selector)).toBe(expected, { x: '14' }, new Error('too bad')); expectSubscriptions(a.subscriptions).toBe(asubs); }); @@ -248,7 +251,7 @@ describe('Observable.prototype.zipAll', () => { const bsubs = '^'; const expected = '---x---y---z'; - expectObservable(Observable.of(a, b).zipAll((e1: string, e2: string) => e1 + e2)) + expectObservable(Observable.of(a, b).zipAll((e1, e2) => e1 + e2)) .toBe(expected, { x: '14', y: '25', z: '36' }); expectSubscriptions(a.subscriptions).toBe(asubs); expectSubscriptions(b.subscriptions).toBe(bsubs); @@ -262,7 +265,7 @@ describe('Observable.prototype.zipAll', () => { const c = hot('---1-^---3---6-| '); const expected = '----x---y-| '; - expectObservable(Observable.of(a, b, c).zipAll()).toBe(expected, + expectObservable(Observable.of(a, b, c).zipAll()).toBe(expected, { x: ['1', '2', '3'], y: ['4', '5', '6'] }); expectSubscriptions(a.subscriptions).toBe(asubs); expectSubscriptions(b.subscriptions).toBe(bsubs); @@ -276,7 +279,7 @@ describe('Observable.prototype.zipAll', () => { const c = hot('---1-^---3---6-| '); const expected = '----x---y-| '; - const observable = Observable.of(a, b, c).zipAll((r0, r1, r2) => [r0, r1, r2]); + const observable = Observable.of(a, b, c).zipAll((r0, r1, r2) => [r0, r1, r2]); expectObservable(observable).toBe(expected, { x: ['1', '2', '3'], y: ['4', '5', '6'] }); expectSubscriptions(a.subscriptions).toBe(asubs); @@ -291,7 +294,7 @@ describe('Observable.prototype.zipAll', () => { const c = hot('---1-^---3---6-| '); const expected = '----x---y-| '; - const observable = Observable.of(a, b, c).zipAll((r0, r1, r2) => [r0, r1, r2]); + const observable = Observable.of(a, b, c).zipAll((r0, r1, r2) => [r0, r1, r2]); expectObservable(observable).toBe(expected, { x: ['1', '2', '3'], y: ['4', '5', '6'] }); expectSubscriptions(a.subscriptions).toBe(asubs); @@ -305,7 +308,7 @@ describe('Observable.prototype.zipAll', () => { const bsubs = '^ ! '; const expected = '---a--b--c--d--e--| '; - expectObservable(Observable.of(a, b).zipAll((r1: string, r2: string) => r1 + r2)) + expectObservable(Observable.of(a, b).zipAll((r1, r2) => r1 + r2)) .toBe(expected, { a: '12', b: '34', c: '56', d: '78', e: '90' }); expectSubscriptions(a.subscriptions).toBe(asubs); expectSubscriptions(b.subscriptions).toBe(bsubs); @@ -318,7 +321,7 @@ describe('Observable.prototype.zipAll', () => { const bsubs = '^ ! '; const expected = '---a--b--c--d--e--| '; - expectObservable(Observable.of(a, b).zipAll((r1: string, r2: string) => r1 + r2)) + expectObservable(Observable.of(a, b).zipAll((r1, r2) => r1 + r2)) .toBe(expected, { a: '21', b: '43', c: '65', d: '87', e: '09' }); expectSubscriptions(a.subscriptions).toBe(asubs); expectSubscriptions(b.subscriptions).toBe(bsubs); @@ -331,7 +334,7 @@ describe('Observable.prototype.zipAll', () => { const bsubs = '^ ! '; const expected = '---a--b--c--d--e-| '; - expectObservable(Observable.of(a, b).zipAll((r1: string, r2: string) => r1 + r2)) + expectObservable(Observable.of(a, b).zipAll((r1, r2) => r1 + r2)) .toBe(expected, { a: '12', b: '34', c: '56', d: '78', e: '90' }); expectSubscriptions(a.subscriptions).toBe(asubs); expectSubscriptions(b.subscriptions).toBe(bsubs); @@ -344,13 +347,13 @@ describe('Observable.prototype.zipAll', () => { const bsubs = '^ ! '; const expected = '---x----# '; - const selector = function (x, y) { + const selector = function (x: string, y: string) { if (y === '5') { throw new Error('too bad'); } else { return x + y; }}; - const observable = Observable.of(a, b).zipAll(selector); + const observable = Observable.of(a, b).zipAll(selector); expectObservable(observable).toBe(expected, { x: '23' }, new Error('too bad')); expectSubscriptions(a.subscriptions).toBe(asubs); @@ -369,15 +372,15 @@ describe('Observable.prototype.zipAll', () => { expectSubscriptions(b.subscriptions).toBe(bsubs); }); - it('should zip until one child terminates', (done: MochaDone) => { + it('should zip until one child terminates', (done) => { const expected = ['a1', 'b2']; let i = 0; - Observable.of( - Observable.of('a', 'b', 'c'), - Observable.of(1, 2) + Observable.of( + Observable.of('a', 'b', 'c'), + Observable.of(1, 2) ) - .zipAll((a: any, b: any) => a + b) - .subscribe((x: any) => { + .zipAll((a, b) => a + b) + .subscribe((x) => { expect(x).to.equal(expected[i++]); }, null, done); }); @@ -465,7 +468,7 @@ describe('Observable.prototype.zipAll', () => { const bsubs = '^'; const expected = '-'; - expectObservable(Observable.of(a, b).zipAll()).toBe(expected); + expectObservable(Observable.of(a, b).zipAll()).toBe(expected); expectSubscriptions(a.subscriptions).toBe(asubs); expectSubscriptions(b.subscriptions).toBe(bsubs); }); @@ -477,7 +480,7 @@ describe('Observable.prototype.zipAll', () => { const bsubs = '(^!)'; const expected = '|'; - expectObservable(Observable.of(a, b).zipAll()).toBe(expected); + expectObservable(Observable.of(a, b).zipAll()).toBe(expected); expectSubscriptions(a.subscriptions).toBe(asubs); expectSubscriptions(b.subscriptions).toBe(bsubs); }); @@ -489,7 +492,7 @@ describe('Observable.prototype.zipAll', () => { const bsubs = '(^!)'; const expected = '|'; - expectObservable(Observable.of(a, b).zipAll()).toBe(expected); + expectObservable(Observable.of(a, b).zipAll()).toBe(expected); expectSubscriptions(a.subscriptions).toBe(asubs); expectSubscriptions(b.subscriptions).toBe(bsubs); }); @@ -501,7 +504,7 @@ describe('Observable.prototype.zipAll', () => { const bsubs = '(^!)'; const expected = '|'; - expectObservable(Observable.of(a, b).zipAll()).toBe(expected); + expectObservable(Observable.of(a, b).zipAll()).toBe(expected); expectSubscriptions(a.subscriptions).toBe(asubs); expectSubscriptions(b.subscriptions).toBe(bsubs); }); @@ -513,7 +516,7 @@ describe('Observable.prototype.zipAll', () => { const bsubs = '(^!)'; const expected = '|'; - expectObservable(Observable.of(a, b).zipAll()).toBe(expected); + expectObservable(Observable.of(a, b).zipAll()).toBe(expected); expectSubscriptions(a.subscriptions).toBe(asubs); expectSubscriptions(b.subscriptions).toBe(bsubs); }); @@ -525,7 +528,7 @@ describe('Observable.prototype.zipAll', () => { const bsubs = '(^!)'; const expected = '|'; - expectObservable(Observable.of(a, b).zipAll()).toBe(expected); + expectObservable(Observable.of(a, b).zipAll()).toBe(expected); expectSubscriptions(a.subscriptions).toBe(asubs); expectSubscriptions(b.subscriptions).toBe(bsubs); }); @@ -537,7 +540,7 @@ describe('Observable.prototype.zipAll', () => { const bsubs = '^ !'; const expected = '-'; - expectObservable(Observable.of(a, b).zipAll()).toBe(expected); + expectObservable(Observable.of(a, b).zipAll()).toBe(expected); expectSubscriptions(a.subscriptions).toBe(asubs); expectSubscriptions(b.subscriptions).toBe(bsubs); }); @@ -549,7 +552,7 @@ describe('Observable.prototype.zipAll', () => { const bsubs = '^'; const expected = '-'; - expectObservable(Observable.of(a, b).zipAll()).toBe(expected); + expectObservable(Observable.of(a, b).zipAll()).toBe(expected); expectSubscriptions(a.subscriptions).toBe(asubs); expectSubscriptions(b.subscriptions).toBe(bsubs); }); @@ -561,7 +564,7 @@ describe('Observable.prototype.zipAll', () => { const bsubs = '^'; const expected = '---x---y---z'; - expectObservable(Observable.of(a, b).zipAll()) + expectObservable(Observable.of(a, b).zipAll()) .toBe(expected, { x: ['1', '4'], y: ['2', '5'], z: ['3', '6'] }); expectSubscriptions(a.subscriptions).toBe(asubs); expectSubscriptions(b.subscriptions).toBe(bsubs); @@ -574,7 +577,7 @@ describe('Observable.prototype.zipAll', () => { const bsubs = '(^!)'; const expected = '|'; - expectObservable(Observable.of(a, b).zipAll()).toBe(expected); + expectObservable(Observable.of(a, b).zipAll()).toBe(expected); expectSubscriptions(a.subscriptions).toBe(asubs); expectSubscriptions(b.subscriptions).toBe(bsubs); }); @@ -586,7 +589,7 @@ describe('Observable.prototype.zipAll', () => { const bsubs = '(^!)'; const expected = '|'; - expectObservable(Observable.of(a, b).zipAll()).toBe(expected); + expectObservable(Observable.of(a, b).zipAll()).toBe(expected); expectSubscriptions(a.subscriptions).toBe(asubs); expectSubscriptions(b.subscriptions).toBe(bsubs); }); @@ -598,7 +601,7 @@ describe('Observable.prototype.zipAll', () => { const bsubs = '^ ! '; const expected = '------# '; - expectObservable(Observable.of(a, b).zipAll()).toBe(expected); + expectObservable(Observable.of(a, b).zipAll()).toBe(expected); expectSubscriptions(a.subscriptions).toBe(asubs); expectSubscriptions(b.subscriptions).toBe(bsubs); }); @@ -610,7 +613,7 @@ describe('Observable.prototype.zipAll', () => { const bsubs = '^ !'; const expected = '------#'; - expectObservable(Observable.of(a, b).zipAll()).toBe(expected); + expectObservable(Observable.of(a, b).zipAll()).toBe(expected); expectSubscriptions(a.subscriptions).toBe(asubs); expectSubscriptions(b.subscriptions).toBe(bsubs); }); @@ -622,7 +625,7 @@ describe('Observable.prototype.zipAll', () => { const bsubs = '^ !'; const expected = '------#'; - expectObservable(Observable.of(a, b).zipAll()).toBe(expected); + expectObservable(Observable.of(a, b).zipAll()).toBe(expected); expectSubscriptions(a.subscriptions).toBe(asubs); expectSubscriptions(b.subscriptions).toBe(bsubs); }); @@ -634,7 +637,7 @@ describe('Observable.prototype.zipAll', () => { const bsubs = '^ !'; const expected = '------#'; - expectObservable(Observable.of(a, b).zipAll()).toBe(expected, null, 'too bad'); + expectObservable(Observable.of(a, b).zipAll()).toBe(expected, null, 'too bad'); expectSubscriptions(a.subscriptions).toBe(asubs); expectSubscriptions(b.subscriptions).toBe(bsubs); }); @@ -646,7 +649,7 @@ describe('Observable.prototype.zipAll', () => { const bsubs = '^ !'; const expected = '-----x--#'; - expectObservable(Observable.of(a, b).zipAll()).toBe(expected, { x: [1, 2] }, 'too bad'); + expectObservable(Observable.of(a, b).zipAll()).toBe(expected, { x: [1, 2] }, 'too bad'); expectSubscriptions(a.subscriptions).toBe(asubs); expectSubscriptions(b.subscriptions).toBe(bsubs); }); @@ -658,7 +661,7 @@ describe('Observable.prototype.zipAll', () => { const bsubs = '^ !'; const expected = '-----x--#'; - expectObservable(Observable.of(a, b).zipAll()).toBe(expected, { x: [2, 1] }, 'too bad'); + expectObservable(Observable.of(a, b).zipAll()).toBe(expected, { x: [2, 1] }, 'too bad'); expectSubscriptions(a.subscriptions).toBe(asubs); expectSubscriptions(b.subscriptions).toBe(bsubs); }); @@ -670,33 +673,33 @@ describe('Observable.prototype.zipAll', () => { const bsubs = '(^!)'; const expected = '#'; - expectObservable(Observable.of(a, b).zipAll()).toBe(expected); + expectObservable(Observable.of(a, b).zipAll()).toBe(expected); expectSubscriptions(a.subscriptions).toBe(asubs); expectSubscriptions(b.subscriptions).toBe(bsubs); }); - it('should combine two immediately-scheduled observables', (done: MochaDone) => { - const a = Observable.of(1, 2, 3, queueScheduler); - const b = Observable.of(4, 5, 6, 7, 8, queueScheduler); + it('should combine two immediately-scheduled observables', (done) => { + const a = Observable.of(1, 2, 3, queueScheduler); + const b = Observable.of(4, 5, 6, 7, 8, queueScheduler); const r = [[1, 4], [2, 5], [3, 6]]; let i = 0; - const result = Observable.of(a, b, queueScheduler).zipAll(); + const result = Observable.of(a, b, queueScheduler).zipAll(); - result.subscribe((vals: any) => { + result.subscribe((vals) => { expect(vals).to.deep.equal(r[i++]); }, null, done); }); - it('should combine a source with an immediately-scheduled source', (done: MochaDone) => { - const a = Observable.of(1, 2, 3, queueScheduler); - const b = Observable.of(4, 5, 6, 7, 8); + it('should combine a source with an immediately-scheduled source', (done) => { + const a = Observable.of(1, 2, 3, queueScheduler); + const b = Observable.of(4, 5, 6, 7, 8); const r = [[1, 4], [2, 5], [3, 6]]; let i = 0; - const result = Observable.of(a, b, queueScheduler).zipAll(); + const result = Observable.of(a, b, queueScheduler).zipAll(); - result.subscribe((vals: any) => { + result.subscribe((vals) => { expect(vals).to.deep.equal(r[i++]); }, null, done); }); @@ -710,10 +713,10 @@ describe('Observable.prototype.zipAll', () => { const expected = '---x---y--'; const values = { x: ['1', '4'], y: ['2', '5']}; - const r = Observable.of(a, b) - .mergeMap((x: string) => Observable.of(x)) + const r = Observable.of(a, b) + .mergeMap((x) => Observable.of(x)) .zipAll() - .mergeMap((x: any) => Observable.of(x)); + .mergeMap((x) => Observable.of(x)); expectObservable(r, unsub).toBe(expected, values); expectSubscriptions(a.subscriptions).toBe(asubs); @@ -726,4 +729,104 @@ describe('Observable.prototype.zipAll', () => { expectObservable(source.zipAll()).toBe(expected); }); + + type(() => { + /* tslint:disable:no-unused-variable */ + const source1 = Rx.Observable.of(1, 2, 3); + const source2 = [1, 2, 3]; + const source3 = new Promise(d => d(1)); + + let result: Rx.Observable = Rx.Observable + .of(source1, source2, source3) + .pipe(Rx.operators.zipAll()); + /* tslint:enable:no-unused-variable */ + }); + + type(() => { + /* tslint:disable:no-unused-variable */ + const source1 = Rx.Observable.of(1, 2, 3); + const source2 = [1, 2, 3]; + const source3 = new Promise(d => d(1)); + + let result: Rx.Observable = Rx.Observable + .of(source1, source2, source3) + .pipe(Rx.operators.zipAll((...args) => args.reduce((acc, x) => acc + x, 0))); + /* tslint:enable:no-unused-variable */ + }); + + type(() => { + /* tslint:disable:no-unused-variable */ + const source1 = Rx.Observable.of(1, 2, 3); + const source2 = [1, 2, 3]; + const source3 = new Promise(d => d(1)); + + let result: Rx.Observable = Rx.Observable + .of(source1, source2, source3) + .zipAll(); + /* tslint:enable:no-unused-variable */ + }); + + type(() => { + /* tslint:disable:no-unused-variable */ + const source1 = Rx.Observable.of(1, 2, 3); + const source2 = [1, 2, 3]; + const source3 = new Promise(d => d(1)); + + let result: Rx.Observable = Rx.Observable + .of(source1, source2, source3) + .zipAll((...args) => args.reduce((acc, x) => acc + x, 0)); + /* tslint:enable:no-unused-variable */ + }); + + type(() => { + // coerce type to a specific type + /* tslint:disable:no-unused-variable */ + const source1 = Rx.Observable.of(1, 2, 3); + const source2 = [1, 2, 3]; + const source3 = new Promise(d => d(1)); + + let result: Rx.Observable = Rx.Observable + .of(source1, source2, source3) + .pipe(Rx.operators.zipAll()); + /* tslint:enable:no-unused-variable */ + }); + + type(() => { + // coerce type to a specific type + /* tslint:disable:no-unused-variable */ + const source1 = Rx.Observable.of(1, 2, 3); + const source2 = [1, 2, 3]; + const source3 = new Promise(d => d(1)); + + let result: Rx.Observable = Rx.Observable + .of(source1, source2, source3) + .pipe(Rx.operators.zipAll((...args) => args.reduce((acc, x) => acc + x, 0))); + /* tslint:enable:no-unused-variable */ + }); + + type(() => { + // coerce type to a specific type + /* tslint:disable:no-unused-variable */ + const source1 = Rx.Observable.of(1, 2, 3); + const source2 = [1, 2, 3]; + const source3 = new Promise(d => d(1)); + + let result: Rx.Observable = Rx.Observable + .of(source1, source2, source3) + .zipAll(); + /* tslint:enable:no-unused-variable */ + }); + + type(() => { + // coerce type to a specific type + /* tslint:disable:no-unused-variable */ + const source1 = Rx.Observable.of(1, 2, 3); + const source2 = [1, 2, 3]; + const source3 = new Promise(d => d(1)); + + let result: Rx.Observable = Rx.Observable + .of(source1, source2, source3) + .zipAll((...args) => args.reduce((acc, x) => acc + x, 0)); + /* tslint:enable:no-unused-variable */ + }); }); diff --git a/src/internal/observable/concat.ts b/src/internal/observable/concat.ts index a11799457e..a194c9619c 100644 --- a/src/internal/observable/concat.ts +++ b/src/internal/observable/concat.ts @@ -112,5 +112,5 @@ export function concat(...observables: Array | ISched if (observables.length === 1 || (observables.length === 2 && isScheduler(observables[1]))) { return from(observables[0]); } - return concatAll()(of(...observables)) as Observable; + return concatAll()(of(...observables)); } diff --git a/src/internal/observable/merge.ts b/src/internal/observable/merge.ts index b245dd5568..910b4cba4d 100644 --- a/src/internal/observable/merge.ts +++ b/src/internal/observable/merge.ts @@ -97,5 +97,5 @@ export function merge(...observables: Array | ISchedu return >observables[0]; } - return mergeAll(concurrent)(fromArray(observables, scheduler)) as Observable; + return mergeAll(concurrent)(fromArray(observables, scheduler)); } diff --git a/src/internal/operators/combineAll.ts b/src/internal/operators/combineAll.ts index a3549110b4..b714f4518b 100644 --- a/src/internal/operators/combineAll.ts +++ b/src/internal/operators/combineAll.ts @@ -1,7 +1,11 @@ import { CombineLatestOperator } from '../observable/combineLatest'; -import { Observable } from '../Observable'; +import { Observable, ObservableInput } from '../Observable'; import { OperatorFunction } from '../../internal/types'; +export function combineAll(): OperatorFunction, T[]>; +export function combineAll(): OperatorFunction; +export function combineAll(project: (...values: T[]) => R): OperatorFunction, R>; +export function combineAll(project: (...values: Array) => R): OperatorFunction; export function combineAll(project?: (...values: Array) => R): OperatorFunction { return (source: Observable) => source.lift(new CombineLatestOperator(project)); } diff --git a/src/internal/operators/concatAll.ts b/src/internal/operators/concatAll.ts index 0cdcf19d2d..32ffb4aba0 100644 --- a/src/internal/operators/concatAll.ts +++ b/src/internal/operators/concatAll.ts @@ -1,6 +1,10 @@ import { mergeAll } from './mergeAll'; -import { MonoTypeOperatorFunction } from '../../internal/types'; +import { OperatorFunction } from '../../internal/types'; +import { ObservableInput, Observable } from '../Observable'; + +export function concatAll(): OperatorFunction, T>; +export function concatAll(): OperatorFunction; /** * Converts a higher-order Observable into a first-order Observable by @@ -50,6 +54,6 @@ import { MonoTypeOperatorFunction } from '../../internal/types'; * @method concatAll * @owner Observable */ -export function concatAll(): MonoTypeOperatorFunction { - return mergeAll(1); +export function concatAll(): OperatorFunction, T> { + return mergeAll(1); } diff --git a/src/internal/operators/exhaust.ts b/src/internal/operators/exhaust.ts index 101726b8a3..6beea5cc3e 100644 --- a/src/internal/operators/exhaust.ts +++ b/src/internal/operators/exhaust.ts @@ -1,10 +1,13 @@ import { Operator } from '../Operator'; -import { Observable } from '../Observable'; +import { Observable, ObservableInput } from '../Observable'; import { Subscriber } from '../Subscriber'; import { Subscription, TeardownLogic } from '../Subscription'; import { OuterSubscriber } from '../OuterSubscriber'; import { subscribeToResult } from '..//util/subscribeToResult'; -import { MonoTypeOperatorFunction } from '../../internal/types'; +import { OperatorFunction } from '../../internal/types'; + +export function exhaust(): OperatorFunction, T>; +export function exhaust(): OperatorFunction; /** * Converts a higher-order Observable into a first-order Observable by dropping @@ -41,7 +44,7 @@ import { MonoTypeOperatorFunction } from '../../internal/types'; * @method exhaust * @owner Observable */ -export function exhaust(): MonoTypeOperatorFunction { +export function exhaust(): OperatorFunction { return (source: Observable) => source.lift(new SwitchFirstOperator()); } diff --git a/src/internal/operators/expand.ts b/src/internal/operators/expand.ts index 07b3dac31a..ad4c22d7fb 100644 --- a/src/internal/operators/expand.ts +++ b/src/internal/operators/expand.ts @@ -1,4 +1,4 @@ -import { Observable } from '../Observable'; +import { Observable, ObservableInput } from '../Observable'; import { IScheduler } from '../Scheduler'; import { Operator } from '../Operator'; import { Subscriber } from '../Subscriber'; @@ -11,8 +11,8 @@ import { subscribeToResult } from '..//util/subscribeToResult'; import { MonoTypeOperatorFunction, OperatorFunction } from '../../internal/types'; /* tslint:disable:max-line-length */ -export function expand(project: (value: T, index: number) => Observable, concurrent?: number, scheduler?: IScheduler): MonoTypeOperatorFunction; -export function expand(project: (value: T, index: number) => Observable, concurrent?: number, scheduler?: IScheduler): OperatorFunction; +export function expand(project: (value: T, index: number) => ObservableInput, concurrent?: number, scheduler?: IScheduler): OperatorFunction; +export function expand(project: (value: T, index: number) => ObservableInput, concurrent?: number, scheduler?: IScheduler): MonoTypeOperatorFunction; /* tslint:enable:max-line-length */ /** @@ -60,7 +60,7 @@ export function expand(project: (value: T, index: number) => Observable * @method expand * @owner Observable */ -export function expand(project: (value: T, index: number) => Observable, +export function expand(project: (value: T, index: number) => ObservableInput, concurrent: number = Number.POSITIVE_INFINITY, scheduler: IScheduler = undefined): OperatorFunction { concurrent = (concurrent || 0) < 1 ? Number.POSITIVE_INFINITY : concurrent; @@ -69,7 +69,7 @@ export function expand(project: (value: T, index: number) => Observable } export class ExpandOperator implements Operator { - constructor(private project: (value: T, index: number) => Observable, + constructor(private project: (value: T, index: number) => ObservableInput, private concurrent: number, private scheduler: IScheduler) { } @@ -81,7 +81,7 @@ export class ExpandOperator implements Operator { interface DispatchArg { subscriber: ExpandSubscriber; - result: Observable; + result: ObservableInput; value: any; index: number; } @@ -98,7 +98,7 @@ export class ExpandSubscriber extends OuterSubscriber { private buffer: any[]; constructor(destination: Subscriber, - private project: (value: T, index: number) => Observable, + private project: (value: T, index: number) => ObservableInput, private concurrent: number, private scheduler: IScheduler) { super(destination); diff --git a/src/internal/operators/mergeAll.ts b/src/internal/operators/mergeAll.ts index 9761ca6308..5d026564d7 100644 --- a/src/internal/operators/mergeAll.ts +++ b/src/internal/operators/mergeAll.ts @@ -1,8 +1,11 @@ -import { ObservableInput } from '../Observable'; +import { ObservableInput, Observable } from '../Observable'; import { mergeMap } from './mergeMap'; import { identity } from '..//util/identity'; -import { MonoTypeOperatorFunction } from '../../internal/types'; +import { OperatorFunction } from '../../internal/types'; + +export function mergeAll(concurrent?: number): OperatorFunction, T>; +export function mergeAll(concurrent?: number): OperatorFunction; /** * Converts a higher-order Observable into a first-order Observable which @@ -48,6 +51,6 @@ import { MonoTypeOperatorFunction } from '../../internal/types'; * @method mergeAll * @owner Observable */ -export function mergeAll(concurrent: number = Number.POSITIVE_INFINITY): MonoTypeOperatorFunction { +export function mergeAll(concurrent: number = Number.POSITIVE_INFINITY): OperatorFunction { return mergeMap(identity as (value: T, index: number) => ObservableInput<{}>, null, concurrent); } diff --git a/src/internal/operators/switchAll.ts b/src/internal/operators/switchAll.ts index d2ce3864fd..3d1e5ae192 100644 --- a/src/internal/operators/switchAll.ts +++ b/src/internal/operators/switchAll.ts @@ -1,8 +1,11 @@ import { OperatorFunction } from '../../internal/types'; -import { Observable } from '../Observable'; +import { ObservableInput } from '../Observable'; import { switchMap } from './switchMap'; import { identity } from '..//util/identity'; -export function switchAll(): OperatorFunction, T> { +export function switchAll(): OperatorFunction, T>; +export function switchAll(): OperatorFunction; + +export function switchAll(): OperatorFunction, T> { return switchMap(identity); } diff --git a/src/internal/operators/zipAll.ts b/src/internal/operators/zipAll.ts index 6f0e925ac7..290a07160e 100644 --- a/src/internal/operators/zipAll.ts +++ b/src/internal/operators/zipAll.ts @@ -1,7 +1,12 @@ import { ZipOperator } from '../observable/zip'; -import { Observable } from '../Observable'; +import { Observable, ObservableInput } from '../Observable'; import { OperatorFunction } from '../../internal/types'; +export function zipAll(): OperatorFunction, T[]>; +export function zipAll(): OperatorFunction; +export function zipAll(project: (...values: T[]) => R): OperatorFunction, R>; +export function zipAll(project: (...values: Array) => R): OperatorFunction; + export function zipAll(project?: (...values: Array) => R): OperatorFunction { return (source: Observable) => source.lift(new ZipOperator(project)); } diff --git a/src/internal/patching/operator/combineAll.ts b/src/internal/patching/operator/combineAll.ts index 927ef0c94f..bdb65b1bde 100644 --- a/src/internal/patching/operator/combineAll.ts +++ b/src/internal/patching/operator/combineAll.ts @@ -1,7 +1,13 @@ -import { Observable } from '../../Observable'; +import { Observable, ObservableInput } from '../../Observable'; import { combineAll as higherOrder } from '../../operators/combineAll'; +export function combineAll(this: Observable>): Observable; +export function combineAll(this: Observable): Observable; +export function combineAll(this: Observable>, project: (...values: T[]) => R): Observable; +export function combineAll(this: Observable, project: (...values: T[]) => R): Observable; +export function combineAll(this: Observable, project: (...values: any[]) => R): Observable; + /** * Converts a higher-order Observable into a first-order Observable by waiting * for the outer Observable to complete, then applying {@link combineLatest}. @@ -42,6 +48,6 @@ import { combineAll as higherOrder } from '../../operators/combineAll'; * @method combineAll * @owner Observable */ -export function combineAll(this: Observable, project?: (...values: Array) => R): Observable { +export function combineAll(this: Observable>, project?: (...values: Array) => R): Observable { return higherOrder(project)(this); } diff --git a/src/internal/patching/operator/concatAll.ts b/src/internal/patching/operator/concatAll.ts index 4e55069969..bc1a89a950 100644 --- a/src/internal/patching/operator/concatAll.ts +++ b/src/internal/patching/operator/concatAll.ts @@ -1,11 +1,8 @@ -import { Observable } from '../../Observable'; -import { Subscribable } from '../../Observable'; +import { Observable, ObservableInput } from '../../Observable'; import { concatAll as higherOrder } from '../../operators/concatAll'; -/* tslint:disable:max-line-length */ -export function concatAll(this: Observable): T; -export function concatAll(this: Observable): Subscribable; -/* tslint:enable:max-line-length */ +export function concatAll(this: Observable>): Observable; +export function concatAll(this: Observable): Observable; /** * Converts a higher-order Observable into a first-order Observable by @@ -55,6 +52,6 @@ export function concatAll(this: Observable): Subscribable; * @method concatAll * @owner Observable */ -export function concatAll(this: Observable): T { - return higherOrder()(this); +export function concatAll(this: Observable>): Observable { + return higherOrder()(this); } diff --git a/src/internal/patching/operator/exhaust.ts b/src/internal/patching/operator/exhaust.ts index 3297c31a40..c160c2febf 100644 --- a/src/internal/patching/operator/exhaust.ts +++ b/src/internal/patching/operator/exhaust.ts @@ -1,7 +1,10 @@ -import { Observable } from '../../Observable'; +import { Observable, ObservableInput } from '../../Observable'; import { exhaust as higherOrder } from '../../operators/exhaust'; +export function exhaust(this: Observable>): Observable; +export function exhaust(this: Observable): Observable; + /** * Converts a higher-order Observable into a first-order Observable by dropping * inner Observables while the previous inner Observable has not yet completed. @@ -37,6 +40,6 @@ import { exhaust as higherOrder } from '../../operators/exhaust'; * @method exhaust * @owner Observable */ -export function exhaust(this: Observable): Observable { - return higherOrder()(this) as Observable; +export function exhaust(this: Observable>): Observable { + return higherOrder()(this); } diff --git a/src/internal/patching/operator/expand.ts b/src/internal/patching/operator/expand.ts index 806af3bf8d..f4dfc90c3a 100644 --- a/src/internal/patching/operator/expand.ts +++ b/src/internal/patching/operator/expand.ts @@ -1,10 +1,10 @@ -import { Observable } from '../../Observable'; +import { Observable, ObservableInput } from '../../Observable'; import { IScheduler } from '../../Scheduler'; import { expand as higherOrder } from '../../operators/expand'; /* tslint:disable:max-line-length */ -export function expand(this: Observable, project: (value: T, index: number) => Observable, concurrent?: number, scheduler?: IScheduler): Observable; -export function expand(this: Observable, project: (value: T, index: number) => Observable, concurrent?: number, scheduler?: IScheduler): Observable; +export function expand(this: Observable, project: (value: T, index: number) => ObservableInput, concurrent?: number, scheduler?: IScheduler): Observable; +export function expand(this: Observable, project: (value: T, index: number) => ObservableInput, concurrent?: number, scheduler?: IScheduler): Observable; /* tslint:enable:max-line-length */ /** @@ -52,7 +52,7 @@ export function expand(this: Observable, project: (value: T, index: num * @method expand * @owner Observable */ -export function expand(this: Observable, project: (value: T, index: number) => Observable, +export function expand(this: Observable, project: (value: T, index: number) => ObservableInput, concurrent: number = Number.POSITIVE_INFINITY, scheduler: IScheduler = undefined): Observable { concurrent = (concurrent || 0) < 1 ? Number.POSITIVE_INFINITY : concurrent; diff --git a/src/internal/patching/operator/mergeAll.ts b/src/internal/patching/operator/mergeAll.ts index ddca2cf30c..50b27127ed 100644 --- a/src/internal/patching/operator/mergeAll.ts +++ b/src/internal/patching/operator/mergeAll.ts @@ -1,9 +1,8 @@ -import { Observable } from '../../Observable'; -import { Subscribable } from '../../Observable'; +import { Observable, ObservableInput } from '../../Observable'; import { mergeAll as higherOrder } from '../../operators/mergeAll'; -export function mergeAll(this: Observable, concurrent?: number): T; -export function mergeAll(this: Observable, concurrent?: number): Subscribable; +export function mergeAll(this: Observable>, concurrent?: number): Observable; +export function mergeAll(this: Observable, concurrent?: number): Observable; /** * Converts a higher-order Observable into a first-order Observable which @@ -49,6 +48,6 @@ export function mergeAll(this: Observable, concurrent?: number): Subscr * @method mergeAll * @owner Observable */ -export function mergeAll(this: Observable, concurrent: number = Number.POSITIVE_INFINITY): Observable { - return higherOrder(concurrent)(this) as Observable; +export function mergeAll(this: Observable>, concurrent: number = Number.POSITIVE_INFINITY): Observable { + return higherOrder(concurrent)(this); } diff --git a/src/internal/patching/operator/switch.ts b/src/internal/patching/operator/switch.ts index 8fbf127b9e..429ebd218c 100644 --- a/src/internal/patching/operator/switch.ts +++ b/src/internal/patching/operator/switch.ts @@ -1,6 +1,9 @@ -import { Observable } from '../../Observable'; +import { Observable, ObservableInput } from '../../Observable'; import { switchAll as higherOrder } from '../../operators/switchAll'; +export function _switch(this: Observable>): Observable; +export function _switch(this: Observable): Observable; + /** * Converts a higher-order Observable into a first-order Observable by * subscribing to only the most recently emitted of those inner Observables. @@ -43,6 +46,6 @@ import { switchAll as higherOrder } from '../../operators/switchAll'; * @name switch * @owner Observable */ -export function _switch(this: Observable>): Observable { +export function _switch(this: Observable>): Observable { return higherOrder()(this) as Observable; } diff --git a/src/internal/patching/operator/zipAll.ts b/src/internal/patching/operator/zipAll.ts index 757ed641a2..2ad7bed2b2 100644 --- a/src/internal/patching/operator/zipAll.ts +++ b/src/internal/patching/operator/zipAll.ts @@ -1,12 +1,17 @@ -import { Observable } from '../../Observable'; +import { Observable, ObservableInput } from '../../Observable'; import { zipAll as higherOrder } from '../../operators/zipAll'; +export function zipAll(this: Observable>): Observable; +export function zipAll(this: Observable): Observable; +export function zipAll(this: Observable>, project: (...values: T[]) => R): Observable; +export function zipAll(this: Observable, project: (...values: T[]) => R): Observable; +export function zipAll(this: Observable, project: (...values: any[]) => R): Observable; /** * @param project * @return {Observable|WebSocketSubject|Observable} * @method zipAll * @owner Observable */ -export function zipAll(this: Observable, project?: (...values: Array) => R): Observable { - return higherOrder(project)(this); +export function zipAll(this: Observable>, project?: (...values: Array) => R): Observable { + return higherOrder(project)(this); }