Skip to content

Commit c84c4a6

Browse files
fix(typings): fix typings for error prone operators like concatAll (#2690)
fixes concatAll, combineAll, exhaust, mergeAll, switch, zipAll. Also made a few improvements to how hot and cold observables are typed. A few compiler errors were fixed due to this change. fixes #2658 #2493 #2551
1 parent 5ffb1d6 commit c84c4a6

21 files changed

+503
-274
lines changed

spec/helpers/marble-testing.ts

Lines changed: 48 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,49 @@
1-
import {Observable} from '../../dist/cjs/Observable';
2-
import {SubscriptionLog} from '../../dist/cjs/testing/SubscriptionLog';
3-
import {ColdObservable} from '../../dist/cjs/testing/ColdObservable';
4-
import {HotObservable} from '../../dist/cjs/testing/HotObservable';
5-
import {TestScheduler, observableToBeFn, subscriptionLogsToBeFn} from '../../dist/cjs/testing/TestScheduler';
6-
7-
declare const global: any;
8-
9-
export const rxTestScheduler: TestScheduler = global.rxTestScheduler;
10-
11-
export function hot(marbles: string, values?: any, error?: any): HotObservable<any> {
12-
if (!global.rxTestScheduler) {
13-
throw 'tried to use hot() in async test';
14-
}
15-
return global.rxTestScheduler.createHotObservable.apply(global.rxTestScheduler, arguments);
16-
}
17-
18-
export function cold(marbles: string, values?: any, error?: any): ColdObservable<any> {
19-
if (!global.rxTestScheduler) {
20-
throw 'tried to use cold() in async test';
21-
}
22-
return global.rxTestScheduler.createColdObservable.apply(global.rxTestScheduler, arguments);
23-
}
24-
25-
export function expectObservable(observable: Observable<any>,
26-
unsubscriptionMarbles: string = null): ({ toBe: observableToBeFn }) {
27-
if (!global.rxTestScheduler) {
28-
throw 'tried to use expectObservable() in async test';
29-
}
30-
return global.rxTestScheduler.expectObservable.apply(global.rxTestScheduler, arguments);
31-
}
32-
33-
export function expectSubscriptions(actualSubscriptionLogs: SubscriptionLog[]): ({ toBe: subscriptionLogsToBeFn }) {
34-
if (!global.rxTestScheduler) {
35-
throw 'tried to use expectSubscriptions() in async test';
36-
}
37-
return global.rxTestScheduler.expectSubscriptions.apply(global.rxTestScheduler, arguments);
38-
}
39-
40-
export function time(marbles: string): number {
41-
if (!global.rxTestScheduler) {
42-
throw 'tried to use time() in async test';
43-
}
44-
return global.rxTestScheduler.createTime.apply(global.rxTestScheduler, arguments);
1+
import {Observable} from '../../dist/cjs/Observable';
2+
import {SubscriptionLog} from '../../dist/cjs/testing/SubscriptionLog';
3+
import {ColdObservable} from '../../dist/cjs/testing/ColdObservable';
4+
import {HotObservable} from '../../dist/cjs/testing/HotObservable';
5+
import {TestScheduler, observableToBeFn, subscriptionLogsToBeFn} from '../../dist/cjs/testing/TestScheduler';
6+
7+
declare const global: any;
8+
9+
export const rxTestScheduler: TestScheduler = global.rxTestScheduler;
10+
11+
export function hot(marbles: string, values?: void, error?: any): HotObservable<string>;
12+
export function hot<V>(marbles: string, values?: { [index: string]: V; }, error?: any): HotObservable<V>;
13+
export function hot<V>(marbles: string, values?: { [index: string]: V; } | void, error?: any): HotObservable<any> {
14+
if (!global.rxTestScheduler) {
15+
throw 'tried to use hot() in async test';
16+
}
17+
return global.rxTestScheduler.createHotObservable.apply(global.rxTestScheduler, arguments);
18+
}
19+
20+
export function cold(marbles: string, values?: void, error?: any): ColdObservable<string>;
21+
export function cold<V>(marbles: string, values?: { [index: string]: V; }, error?: any): ColdObservable<V>;
22+
export function cold<V>(marbles: string, values?: { [index: string]: V; } | void, error?: any): ColdObservable<V> {
23+
if (!global.rxTestScheduler) {
24+
throw 'tried to use cold() in async test';
25+
}
26+
return global.rxTestScheduler.createColdObservable.apply(global.rxTestScheduler, arguments);
27+
}
28+
29+
export function expectObservable(observable: Observable<any>,
30+
unsubscriptionMarbles: string = null): ({ toBe: observableToBeFn }) {
31+
if (!global.rxTestScheduler) {
32+
throw 'tried to use expectObservable() in async test';
33+
}
34+
return global.rxTestScheduler.expectObservable.apply(global.rxTestScheduler, arguments);
35+
}
36+
37+
export function expectSubscriptions(actualSubscriptionLogs: SubscriptionLog[]): ({ toBe: subscriptionLogsToBeFn }) {
38+
if (!global.rxTestScheduler) {
39+
throw 'tried to use expectSubscriptions() in async test';
40+
}
41+
return global.rxTestScheduler.expectSubscriptions.apply(global.rxTestScheduler, arguments);
42+
}
43+
44+
export function time(marbles: string): number {
45+
if (!global.rxTestScheduler) {
46+
throw 'tried to use time() in async test';
47+
}
48+
return global.rxTestScheduler.createTime.apply(global.rxTestScheduler, arguments);
4549
}

0 commit comments

Comments
 (0)