11import { of , forkJoin } from 'rxjs' ;
22
3- it ( 'should infer correctly with 1 parameter' , ( ) => {
4- const a = of ( 1 , 2 , 3 ) ;
5- const res = forkJoin ( a ) ; // $ExpectType Observable<number[]>
6- } ) ;
3+ describe ( 'deprecated rest args' , ( ) => {
4+ it ( 'should infer correctly with 1 parameter' , ( ) => {
5+ const a = of ( 1 , 2 , 3 ) ;
6+ const res = forkJoin ( a ) ; // $ExpectType Observable<[number]>
7+ } ) ;
78
8- it ( 'should infer correctly with 2 parameters' , ( ) => {
9- const a = of ( 1 , 2 , 3 ) ;
10- const b = of ( 'a' , 'b' , 'c' ) ;
11- const res = forkJoin ( a , b ) ; // $ExpectType Observable<[number, string]>
12- } ) ;
9+ it ( 'should infer correctly with 2 parameters' , ( ) => {
10+ const a = of ( 1 , 2 , 3 ) ;
11+ const b = of ( 'a' , 'b' , 'c' ) ;
12+ const res = forkJoin ( a , b ) ; // $ExpectType Observable<[number, string]>
13+ } ) ;
1314
14- it ( 'should infer correctly with 3 parameters' , ( ) => {
15- const a = of ( 1 , 2 , 3 ) ;
16- const b = of ( 'a' , 'b' , 'c' ) ;
17- const c = of ( 1 , 2 , 3 ) ;
18- const res = forkJoin ( a , b , c ) ; // $ExpectType Observable<[number, string, number]>
19- } ) ;
15+ it ( 'should infer correctly with 3 parameters' , ( ) => {
16+ const a = of ( 1 , 2 , 3 ) ;
17+ const b = of ( 'a' , 'b' , 'c' ) ;
18+ const c = of ( 1 , 2 , 3 ) ;
19+ const res = forkJoin ( a , b , c ) ; // $ExpectType Observable<[number, string, number]>
20+ } ) ;
2021
21- it ( 'should infer correctly with 4 parameters' , ( ) => {
22- const a = of ( 1 , 2 , 3 ) ;
23- const b = of ( 'a' , 'b' , 'c' ) ;
24- const c = of ( 1 , 2 , 3 ) ;
25- const d = of ( 1 , 2 , 3 ) ;
26- const res = forkJoin ( a , b , c , d ) ; // $ExpectType Observable<[number, string, number, number]>
27- } ) ;
22+ it ( 'should infer correctly with 4 parameters' , ( ) => {
23+ const a = of ( 1 , 2 , 3 ) ;
24+ const b = of ( 'a' , 'b' , 'c' ) ;
25+ const c = of ( 1 , 2 , 3 ) ;
26+ const d = of ( 1 , 2 , 3 ) ;
27+ const res = forkJoin ( a , b , c , d ) ; // $ExpectType Observable<[number, string, number, number]>
28+ } ) ;
2829
29- it ( 'should infer correctly with 5 parameters' , ( ) => {
30- const a = of ( 1 , 2 , 3 ) ;
31- const b = of ( 'a' , 'b' , 'c' ) ;
32- const c = of ( 1 , 2 , 3 ) ;
33- const d = of ( 1 , 2 , 3 ) ;
34- const e = of ( 1 , 2 , 3 ) ;
35- const res = forkJoin ( a , b , c , d , e ) ; // $ExpectType Observable<[number, string, number, number, number]>
36- } ) ;
30+ it ( 'should infer correctly with 5 parameters' , ( ) => {
31+ const a = of ( 1 , 2 , 3 ) ;
32+ const b = of ( 'a' , 'b' , 'c' ) ;
33+ const c = of ( 1 , 2 , 3 ) ;
34+ const d = of ( 1 , 2 , 3 ) ;
35+ const e = of ( 1 , 2 , 3 ) ;
36+ const res = forkJoin ( a , b , c , d , e ) ; // $ExpectType Observable<[number, string, number, number, number]>
37+ } ) ;
3738
38- it ( 'should infer correctly with 6 parameters' , ( ) => {
39- const a = of ( 1 , 2 , 3 ) ;
40- const b = of ( 'a' , 'b' , 'c' ) ;
41- const c = of ( 1 , 2 , 3 ) ;
42- const d = of ( 1 , 2 , 3 ) ;
43- const e = of ( 1 , 2 , 3 ) ;
44- const f = of ( 1 , 2 , 3 ) ;
45- const res = forkJoin ( a , b , c , d , e , f ) ; // $ExpectType Observable<[number, string, number, number, number, number]>
39+ it ( 'should infer correctly with 6 parameters' , ( ) => {
40+ const a = of ( 1 , 2 , 3 ) ;
41+ const b = of ( 'a' , 'b' , 'c' ) ;
42+ const c = of ( 1 , 2 , 3 ) ;
43+ const d = of ( 1 , 2 , 3 ) ;
44+ const e = of ( 1 , 2 , 3 ) ;
45+ const f = of ( 1 , 2 , 3 ) ;
46+ const res = forkJoin ( a , b , c , d , e , f ) ; // $ExpectType Observable<[number, string, number, number, number, number]>
47+ } ) ;
4648} ) ;
4749
4850it ( 'should infer of type any for more than 6 parameters' , ( ) => {
@@ -56,38 +58,47 @@ it('should infer of type any for more than 6 parameters', () => {
5658 const res = forkJoin ( a , b , c , d , e , f , g ) ; // $ExpectType Observable<any>
5759} ) ;
5860
59- it ( 'should infer correctly for array of 1 observable' , ( ) => {
60- const a = [ of ( 1 , 2 , 3 ) ] ;
61- const res = forkJoin ( a ) ; // $ExpectType Observable<number[]>
61+ describe ( 'forkJoin({})' , ( ) => {
62+ it ( 'should properly type empty objects' , ( ) => {
63+ const res = forkJoin ( { } ) ; // $ExpectType Observable<never>
64+ } ) ;
65+
66+ it ( 'should work for the simple case' , ( ) => {
67+ const res = forkJoin ( { foo : of ( 1 ) , bar : of ( 'two' ) , baz : of ( false ) } ) ; // $ExpectType Observable<{ foo: number; bar: string; baz: boolean; }>
68+ } ) ;
6269} ) ;
6370
64- // TODO(benlesh): We need to fix forkJoin so these pass
65- // it('should infer correctly for array of 2 observables', () => {
66- // const a = [of(1, 2, 3), of('a', 'b', 'c')];
67- // const res = forkJoin(a); // $ExpectType Observable<[number, string]>
68- // });
69-
70- // it('should infer correctly for array of 3 observables', () => {
71- // const a = [of(1, 2, 3), of('a', 'b', 'c'), of(true, true, false)];
72- // const res = forkJoin(a); // $ExpectType Observable<[number, string, boolean]>
73- // });
74-
75- // it('should infer correctly for array of 4 observables', () => {
76- // const a = [of(1, 2, 3), of('a', 'b', 'c'), of(1, 2, 3), of(1, 2, 3)];
77- // const res = forkJoin(a); // $ExpectType Observable<[number, string, number, number]>
78- // });
79-
80- // it('should infer correctly for array of 5 observables', () => {
81- // const a = [of(1, 2, 3), of('a', 'b', 'c'), of(1, 2, 3), of(1, 2, 3), of(1, 2, 3)];
82- // const res = forkJoin(a); // $ExpectType Observable<[number, string, number, number, number]>
83- // });
84-
85- // it('should infer correctly for array of 6 observables', () => {
86- // const a = [of(1, 2, 3), of('a', 'b', 'c'), of(1, 2, 3), of(1, 2, 3), of(1, 2, 3), of(1, 2, 3)];
87- // const res = forkJoin(a); // $ExpectType Observable<[number, string, number, number, number, number]>
88- // });
89-
90- // it('should force user cast for array of 6+ observables', () => {
91- // const a = [of(1, 2, 3), of('a', 'b', 'c'), of(1, 2, 3), of(1, 2, 3), of(1, 2, 3), of(1, 2, 3), of(1, 2, 3)];
92- // const res = forkJoin(a); // $ExpectType Observable<{}>
93- // });
71+ describe ( 'forkJoin([])' , ( ) => {
72+ // TODO(benlesh): Uncomment for TS 3.0
73+ // it('should properly type empty arrays', () => {
74+ // const res = forkJoin([]); // $ExpectType Observable<never>
75+ // });
76+
77+ it ( 'should infer correctly for array of 1 observable' , ( ) => {
78+ const res = forkJoin ( [ of ( 1 , 2 , 3 ) ] ) ; // $ExpectType Observable<[number]>
79+ } ) ;
80+
81+ it ( 'should infer correctly for array of 2 observables' , ( ) => {
82+ const res = forkJoin ( [ of ( 1 , 2 , 3 ) , of ( 'a' , 'b' , 'c' ) ] ) ; // $ExpectType Observable<[number, string]>
83+ } ) ;
84+
85+ it ( 'should infer correctly for array of 3 observables' , ( ) => {
86+ const res = forkJoin ( [ of ( 1 , 2 , 3 ) , of ( 'a' , 'b' , 'c' ) , of ( true , true , false ) ] ) ; // $ExpectType Observable<[number, string, boolean]>
87+ } ) ;
88+
89+ it ( 'should infer correctly for array of 4 observables' , ( ) => {
90+ const res = forkJoin ( [ of ( 1 , 2 , 3 ) , of ( 'a' , 'b' , 'c' ) , of ( 1 , 2 , 3 ) , of ( 1 , 2 , 3 ) ] ) ; // $ExpectType Observable<[number, string, number, number]>
91+ } ) ;
92+
93+ it ( 'should infer correctly for array of 5 observables' , ( ) => {
94+ const res = forkJoin ( [ of ( 1 , 2 , 3 ) , of ( 'a' , 'b' , 'c' ) , of ( 1 , 2 , 3 ) , of ( 1 , 2 , 3 ) , of ( 1 , 2 , 3 ) ] ) ; // $ExpectType Observable<[number, string, number, number, number]>
95+ } ) ;
96+
97+ it ( 'should infer correctly for array of 6 observables' , ( ) => {
98+ const res = forkJoin ( [ of ( 1 , 2 , 3 ) , of ( 'a' , 'b' , 'c' ) , of ( 1 , 2 , 3 ) , of ( 1 , 2 , 3 ) , of ( 1 , 2 , 3 ) , of ( 1 , 2 , 3 ) ] ) ; // $ExpectType Observable<[number, string, number, number, number, number]>
99+ } ) ;
100+
101+ it ( 'should force user cast for array of 6+ observables' , ( ) => {
102+ const res = forkJoin ( [ of ( 1 , 2 , 3 ) , of ( 'a' , 'b' , 'c' ) , of ( 1 , 2 , 3 ) , of ( 1 , 2 , 3 ) , of ( 1 , 2 , 3 ) , of ( 1 , 2 , 3 ) , of ( 1 , 2 , 3 ) ] ) ; // $ExpectType Observable<(string | number)[]>
103+ } ) ;
104+ } ) ;
0 commit comments