Skip to content

Commit

Permalink
feat(forkJoin): accepts a dictionary of sources (#4640)
Browse files Browse the repository at this point in the history
- Adds `forkJoin({ foo, bar })` such that it will return an `Observable<{ foo, bar }>` containing the values emitted from the sources held at the properties of the passed object.
- DEPRECATED: `forkJoin(a, b, c, d)` should no longer be used, rather, just pass an array such as `forkJoin([a, b, c, d])`.
  • Loading branch information
benlesh committed Apr 23, 2019
1 parent f57e1fc commit b5a2ac9
Show file tree
Hide file tree
Showing 4 changed files with 596 additions and 452 deletions.
153 changes: 82 additions & 71 deletions spec-dtslint/observables/forkJoin-spec.ts
@@ -1,48 +1,50 @@
import { of, forkJoin } from 'rxjs';

it('should infer correctly with 1 parameter', () => {
const a = of(1, 2, 3);
const res = forkJoin(a); // $ExpectType Observable<number[]>
});
describe('deprecated rest args', () => {
it('should infer correctly with 1 parameter', () => {
const a = of(1, 2, 3);
const res = forkJoin(a); // $ExpectType Observable<[number]>
});

it('should infer correctly with 2 parameters', () => {
const a = of(1, 2, 3);
const b = of('a', 'b', 'c');
const res = forkJoin(a, b); // $ExpectType Observable<[number, string]>
});
it('should infer correctly with 2 parameters', () => {
const a = of(1, 2, 3);
const b = of('a', 'b', 'c');
const res = forkJoin(a, b); // $ExpectType Observable<[number, string]>
});

it('should infer correctly with 3 parameters', () => {
const a = of(1, 2, 3);
const b = of('a', 'b', 'c');
const c = of(1, 2, 3);
const res = forkJoin(a, b, c); // $ExpectType Observable<[number, string, number]>
});
it('should infer correctly with 3 parameters', () => {
const a = of(1, 2, 3);
const b = of('a', 'b', 'c');
const c = of(1, 2, 3);
const res = forkJoin(a, b, c); // $ExpectType Observable<[number, string, number]>
});

it('should infer correctly with 4 parameters', () => {
const a = of(1, 2, 3);
const b = of('a', 'b', 'c');
const c = of(1, 2, 3);
const d = of(1, 2, 3);
const res = forkJoin(a, b, c, d); // $ExpectType Observable<[number, string, number, number]>
});
it('should infer correctly with 4 parameters', () => {
const a = of(1, 2, 3);
const b = of('a', 'b', 'c');
const c = of(1, 2, 3);
const d = of(1, 2, 3);
const res = forkJoin(a, b, c, d); // $ExpectType Observable<[number, string, number, number]>
});

it('should infer correctly with 5 parameters', () => {
const a = of(1, 2, 3);
const b = of('a', 'b', 'c');
const c = of(1, 2, 3);
const d = of(1, 2, 3);
const e = of(1, 2, 3);
const res = forkJoin(a, b, c, d, e); // $ExpectType Observable<[number, string, number, number, number]>
});
it('should infer correctly with 5 parameters', () => {
const a = of(1, 2, 3);
const b = of('a', 'b', 'c');
const c = of(1, 2, 3);
const d = of(1, 2, 3);
const e = of(1, 2, 3);
const res = forkJoin(a, b, c, d, e); // $ExpectType Observable<[number, string, number, number, number]>
});

it('should infer correctly with 6 parameters', () => {
const a = of(1, 2, 3);
const b = of('a', 'b', 'c');
const c = of(1, 2, 3);
const d = of(1, 2, 3);
const e = of(1, 2, 3);
const f = of(1, 2, 3);
const res = forkJoin(a, b, c, d, e, f); // $ExpectType Observable<[number, string, number, number, number, number]>
it('should infer correctly with 6 parameters', () => {
const a = of(1, 2, 3);
const b = of('a', 'b', 'c');
const c = of(1, 2, 3);
const d = of(1, 2, 3);
const e = of(1, 2, 3);
const f = of(1, 2, 3);
const res = forkJoin(a, b, c, d, e, f); // $ExpectType Observable<[number, string, number, number, number, number]>
});
});

it('should infer of type any for more than 6 parameters', () => {
Expand All @@ -56,38 +58,47 @@ it('should infer of type any for more than 6 parameters', () => {
const res = forkJoin(a, b, c, d, e, f, g); // $ExpectType Observable<any>
});

it('should infer correctly for array of 1 observable', () => {
const a = [of(1, 2, 3)];
const res = forkJoin(a); // $ExpectType Observable<number[]>
describe('forkJoin({})', () => {
it('should properly type empty objects', () => {
const res = forkJoin({}); // $ExpectType Observable<never>
});

it('should work for the simple case', () => {
const res = forkJoin({ foo: of(1), bar: of('two'), baz: of(false) }); // $ExpectType Observable<{ foo: number; bar: string; baz: boolean; }>
});
});

// TODO(benlesh): We need to fix forkJoin so these pass
// it('should infer correctly for array of 2 observables', () => {
// const a = [of(1, 2, 3), of('a', 'b', 'c')];
// const res = forkJoin(a); // $ExpectType Observable<[number, string]>
// });

// it('should infer correctly for array of 3 observables', () => {
// const a = [of(1, 2, 3), of('a', 'b', 'c'), of(true, true, false)];
// const res = forkJoin(a); // $ExpectType Observable<[number, string, boolean]>
// });

// it('should infer correctly for array of 4 observables', () => {
// const a = [of(1, 2, 3), of('a', 'b', 'c'), of(1, 2, 3), of(1, 2, 3)];
// const res = forkJoin(a); // $ExpectType Observable<[number, string, number, number]>
// });

// it('should infer correctly for array of 5 observables', () => {
// const a = [of(1, 2, 3), of('a', 'b', 'c'), of(1, 2, 3), of(1, 2, 3), of(1, 2, 3)];
// const res = forkJoin(a); // $ExpectType Observable<[number, string, number, number, number]>
// });

// it('should infer correctly for array of 6 observables', () => {
// 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)];
// const res = forkJoin(a); // $ExpectType Observable<[number, string, number, number, number, number]>
// });

// it('should force user cast for array of 6+ observables', () => {
// 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)];
// const res = forkJoin(a); // $ExpectType Observable<{}>
// });
describe('forkJoin([])', () => {
// TODO(benlesh): Uncomment for TS 3.0
// it('should properly type empty arrays', () => {
// const res = forkJoin([]); // $ExpectType Observable<never>
// });

it('should infer correctly for array of 1 observable', () => {
const res = forkJoin([of(1, 2, 3)]); // $ExpectType Observable<[number]>
});

it('should infer correctly for array of 2 observables', () => {
const res = forkJoin([of(1, 2, 3), of('a', 'b', 'c')]); // $ExpectType Observable<[number, string]>
});

it('should infer correctly for array of 3 observables', () => {
const res = forkJoin([of(1, 2, 3), of('a', 'b', 'c'), of(true, true, false)]); // $ExpectType Observable<[number, string, boolean]>
});

it('should infer correctly for array of 4 observables', () => {
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]>
});

it('should infer correctly for array of 5 observables', () => {
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]>
});

it('should infer correctly for array of 6 observables', () => {
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]>
});

it('should force user cast for array of 6+ observables', () => {
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)[]>
});
});

0 comments on commit b5a2ac9

Please sign in to comment.