Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(combineLatestWith): adds combineLatestWith #5251

Merged
merged 1 commit into from
Jan 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 34 additions & 48 deletions spec-dtslint/observables/combineLatest-spec.ts
Original file line number Diff line number Diff line change
@@ -1,139 +1,125 @@
import { of, combineLatest, asyncScheduler } from 'rxjs';

class A { a = 0; }
class B { b = 0; }
class C { c = 0; }
class D { d = 0; }
class E { e = 0; }
class F { f = 0; }
class G { g = 0; }

const a = of(new A());
const b = of(new B());
const c = of(new C());
const d = of(new D());
const e = of(new E());
const f = of(new F());
const g = of(new G());
import { combineLatest } from 'rxjs';
import { a$, b$, c$, d$, e$, f$, g$, A, B, C, D, E, F } from '../helpers';


it('should accept 1 param', () => {
const o = combineLatest(a); // $ExpectType Observable<[A]>
const o = combineLatest(a$); // $ExpectType Observable<[A]>
});

it('should accept 2 params', () => {
const o = combineLatest(a, b); // $ExpectType Observable<[A, B]>
const o = combineLatest(a$, b$); // $ExpectType Observable<[A, B]>
});

it('should accept 3 params', () => {
const o = combineLatest(a, b, c); // $ExpectType Observable<[A, B, C]>
const o = combineLatest(a$, b$, c$); // $ExpectType Observable<[A, B, C]>
});

it('should accept 4 params', () => {
const o = combineLatest(a, b, c, d); // $ExpectType Observable<[A, B, C, D]>
const o = combineLatest(a$, b$, c$, d$); // $ExpectType Observable<[A, B, C, D]>
});

it('should accept 5 params', () => {
const o = combineLatest(a, b, c, d, e); // $ExpectType Observable<[A, B, C, D, E]>
const o = combineLatest(a$, b$, c$, d$, e$); // $ExpectType Observable<[A, B, C, D, E]>
});

it('should accept 6 params', () => {
const o = combineLatest(a, b, c, d, e, f); // $ExpectType Observable<[A, B, C, D, E, F]>
const o = combineLatest(a$, b$, c$, d$, e$, f$); // $ExpectType Observable<[A, B, C, D, E, F]>
});

it('should result in Observable<unknown> for 7 or more params', () => {
const o = combineLatest(a, b, c, d, e, f, g); // $ExpectType Observable<unknown>
const o = combineLatest(a$, b$, c$, d$, e$, f$, g$); // $ExpectType Observable<unknown>
});

it('should accept union types', () => {
const u1: typeof a | typeof b = Math.random() > 0.5 ? a : b;
const u2: typeof c | typeof d = Math.random() > 0.5 ? c : d;
const u1: typeof a$ | typeof b$ = Math.random() > 0.5 ? a$ : b$;
const u2: typeof c$ | typeof d$ = Math.random() > 0.5 ? c$ : d$;
const o = combineLatest(u1, u2); // $ExpectType Observable<[A | B, C | D]>
});

it('should accept 1 param and a result selector', () => {
const o = combineLatest(a, () => new A()); // $ExpectType Observable<A>
const o = combineLatest(a$, () => new A()); // $ExpectType Observable<A>
});

it('should accept 2 params and a result selector', () => {
const o = combineLatest(a, b, () => new A()); // $ExpectType Observable<A>
const o = combineLatest(a$, b$, () => new A()); // $ExpectType Observable<A>
});

it('should accept 3 params and a result selector', () => {
const o = combineLatest(a, b, c, () => new A()); // $ExpectType Observable<A>
const o = combineLatest(a$, b$, c$, () => new A()); // $ExpectType Observable<A>
});

it('should accept 4 params and a result selector', () => {
const o = combineLatest(a, b, c, d, () => new A()); // $ExpectType Observable<A>
const o = combineLatest(a$, b$, c$, d$, () => new A()); // $ExpectType Observable<A>
});

it('should accept 5 params and a result selector', () => {
const o = combineLatest(a, b, c, d, e, () => new A()); // $ExpectType Observable<A>
const o = combineLatest(a$, b$, c$, d$, e$, () => new A()); // $ExpectType Observable<A>
});

it('should accept 6 params and a result selector', () => {
const o = combineLatest(a, b, c, d, e, f, () => new A()); // $ExpectType Observable<A>
const o = combineLatest(a$, b$, c$, d$, e$, f$, () => new A()); // $ExpectType Observable<A>
});

it('should accept 7 or more params and a result selector', () => {
const o = combineLatest(a, b, c, d, e, f, g, g, g, () => new A()); // $ExpectType Observable<A>
const o = combineLatest(a$, b$, c$, d$, e$, f$, g$, g$, g$, () => new A()); // $ExpectType Observable<A>
});

it('should accept 1 param', () => {
const o = combineLatest([a]); // $ExpectType Observable<[A]>
const o = combineLatest([a$]); // $ExpectType Observable<[A]>
});

it('should accept 2 params', () => {
const o = combineLatest([a, b]); // $ExpectType Observable<[A, B]>
const o = combineLatest([a$, b$]); // $ExpectType Observable<[A, B]>
});

it('should accept 3 params', () => {
const o = combineLatest([a, b, c]); // $ExpectType Observable<[A, B, C]>
const o = combineLatest([a$, b$, c$]); // $ExpectType Observable<[A, B, C]>
});

it('should accept 4 params', () => {
const o = combineLatest([a, b, c, d]); // $ExpectType Observable<[A, B, C, D]>
const o = combineLatest([a$, b$, c$, d$]); // $ExpectType Observable<[A, B, C, D]>
});

it('should accept 5 params', () => {
const o = combineLatest([a, b, c, d, e]); // $ExpectType Observable<[A, B, C, D, E]>
const o = combineLatest([a$, b$, c$, d$, e$]); // $ExpectType Observable<[A, B, C, D, E]>
});

it('should accept 6 params', () => {
const o = combineLatest([a, b, c, d, e, f]); // $ExpectType Observable<[A, B, C, D, E, F]>
const o = combineLatest([a$, b$, c$, d$, e$, f$]); // $ExpectType Observable<[A, B, C, D, E, F]>
});

it('should have basic support for 7 or more params', () => {
const o = combineLatest([a, b, c, d, e, f, g]); // $ExpectType Observable<(A | B | C | D | E | F | G)[]>
const o = combineLatest([a$, b$, c$, d$, e$, f$, g$]); // $ExpectType Observable<(A | B | C | D | E | F | G)[]>
});

it('should handle an array of Observables', () => {
const o = combineLatest([a, a, a, a, a, a, a, a, a, a, a]); // $ExpectType Observable<A[]>
const o = combineLatest([a$, a$, a$, a$, a$, a$, a$, a$, a$, a$, a$]); // $ExpectType Observable<A[]>
});

it('should accept 1 param and a result selector', () => {
const o = combineLatest([a], (a: A) => new A()); // $ExpectType Observable<A>
const o = combineLatest([a$], (a: A) => new A()); // $ExpectType Observable<A>
});

it('should accept 2 params and a result selector', () => {
const o = combineLatest([a, b], (a: A, b: B) => new A()); // $ExpectType Observable<A>
const o = combineLatest([a$, b$], (a: A, b: B) => new A()); // $ExpectType Observable<A>
});

it('should accept 3 params and a result selector', () => {
const o = combineLatest([a, b, c], (a: A, b: B, c: C) => new A()); // $ExpectType Observable<A>
const o = combineLatest([a$, b$, c$], (a: A, b: B, c: C) => new A()); // $ExpectType Observable<A>
});

it('should accept 4 params and a result selector', () => {
const o = combineLatest([a, b, c, d], (a: A, b: B, c: C, d: D) => new A()); // $ExpectType Observable<A>
const o = combineLatest([a$, b$, c$, d$], (a: A, b: B, c: C, d: D) => new A()); // $ExpectType Observable<A>
});

it('should accept 5 params and a result selector', () => {
const o = combineLatest([a, b, c, d, e], (a: A, b: B, c: C, d: D, e: E) => new A()); // $ExpectType Observable<A>
const o = combineLatest([a$, b$, c$, d$, e$], (a: A, b: B, c: C, d: D, e: E) => new A()); // $ExpectType Observable<A>
});

it('should accept 6 params and a result selector', () => {
const o = combineLatest([a, b, c, d, e, f], (a: A, b: B, c: C, d: D, e: E, f: F) => new A()); // $ExpectType Observable<A>
const o = combineLatest([a$, b$, c$, d$, e$, f$], (a: A, b: B, c: C, d: D, e: E, f: F) => new A()); // $ExpectType Observable<A>
});

it('should accept 7 or more params and a result selector', () => {
const o = combineLatest([a, b, c, d, e, f, g, g, g], (a: any, b: any, c: any, d: any, e: any, f: any, g1: any, g2: any, g3: any) => new A()); // $ExpectType Observable<A>
const o = combineLatest([a$, b$, c$, d$, e$, f$, g$, g$, g$], (a: any, b: any, c: any, d: any, e: any, f: any, g1: any, g2: any, g3: any) => new A()); // $ExpectType Observable<A>
});
21 changes: 5 additions & 16 deletions spec-dtslint/observables/of-spec.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,5 @@
import { of, animationFrameScheduler, queueScheduler } from 'rxjs';
import { A, B, C, D, E, F, G, H, I, J } from '../helpers';

const a = new A();
const b = new B();
const c = new C();
const d = new D();
const e = new E();
const f = new F();
const g = new G();
const h = new H();
const i = new I();
const j = new J();
import { A, a, b, c, d, e, f, g, h, i, j } from '../helpers';

it('should infer never with 0 params', () => {
const res = of(); // $ExpectType Observable<never>
Expand All @@ -23,7 +12,7 @@ it('forced generic should not cause an issue', () => {
});

it('should infer correctly with 1 param', () => {
const res = of(new A()); // $ExpectType Observable<A>
const res = of(a); // $ExpectType Observable<A>
});

it('should infer correctly with mixed type of 2 params', () => {
Expand Down Expand Up @@ -67,7 +56,7 @@ it('should support mixed type of 9 params', () => {
});

it('should support mixed type of 13 params', () => {
const res = of(a, b, c, d, e, f, g, h, i, j, '', true, 123, [1, 2, 3]); // $ExpectType Observable<string | number | boolean | number[] | A | B | C | D | E | F | G | H | I | J>
const res = of(a, b, c, d, e, f, g, h, i, j, '', true, 123, [1, 2, 3]); // $ExpectType Observable<string | number | boolean | A | B | C | D | E | F | G | number[] | H | I | J>
});

it('should support a rest of params', () => {
Expand Down Expand Up @@ -95,7 +84,7 @@ it('should infer never with 0 params', () => {
});

it('should infer correctly with 1 param', () => {
const res = of(new A(), queueScheduler); // $ExpectType Observable<A>
const res = of(a, queueScheduler); // $ExpectType Observable<A>
});

it('should infer correctly with mixed type of 2 params', () => {
Expand Down Expand Up @@ -140,7 +129,7 @@ it('should deprecate correctly', () => {
of(a, b, c, d, e, f, queueScheduler); // $ExpectDeprecation
of(a, b, c, d, e, f, g, queueScheduler); // $ExpectDeprecation
of(a, b, c, d, e, f, g, h, queueScheduler); // $ExpectDeprecation
of(a, b, c, d, e, f, g, h, i, queueScheduler); // $ExpectDeprecation
of(a, b, c, d, e, f, g, h, i, queueScheduler); // $ExpectDeprecation
of<A>(); // $ExpectDeprecation
of(); // $ExpectNoDeprecation
of(a); // $ExpectNoDeprecation
Expand Down
57 changes: 57 additions & 0 deletions spec-dtslint/operators/combineLatestWith-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { of } from 'rxjs';
import { combineLatestWith } from 'rxjs/operators';

describe('combineLatestWith', () => {
describe('without project parameter', () => {
it('should infer correctly with 1 param', () => {
const a = of(1, 2, 3);
const b = of('a', 'b', 'c');
const res = a.pipe(combineLatestWith(b)); // $ExpectType Observable<[number, string]>
});

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

it('should infer correctly with 3 params', () => {
const a = of(1, 2, 3);
const b = of('a', 'b', 'c');
const c = of('d', 'e', 'f');
const d = of('g', 'h', 'i');
const res = a.pipe(combineLatestWith(b, c, d)); // $ExpectType Observable<[number, string, string, string]>
});

it('should infer correctly with 4 params', () => {
const a = of(1, 2, 3);
const b = of('a', 'b', 'c');
const c = of('d', 'e', 'f');
const d = of('g', 'h', 'i');
const e = of('j', 'k', 'l');
const res = a.pipe(combineLatestWith(b, c, d, e)); // $ExpectType Observable<[number, string, string, string, string]>
});

it('should infer correctly with 5 params', () => {
const a = of(1, 2, 3);
const b = of('a', 'b', 'c');
const c = of('d', 'e', 'f');
const d = of('g', 'h', 'i');
const e = of('j', 'k', 'l');
const f = of('m', 'n', 'o');
const res = a.pipe(combineLatestWith(b, c, d, e, f)); // $ExpectType Observable<[number, string, string, string, string, string]>
});

it('should accept N params', () => {
const a = of(1, 2, 3);
const b = of('a', 'b', 'c');
const c = of('d', 'e', 'f');
const d = of('g', 'h', 'i');
const e = of('j', 'k', 'l');
const f = of('m', 'n', 'o');
const g = of('p', 'q', 'r');
const res = a.pipe(combineLatestWith(b, c, d, e, f, g)); // $ExpectType Observable<(string | number)[]>
});
});
});
6 changes: 3 additions & 3 deletions spec-dtslint/operators/concatWith-spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { of } from 'rxjs';
import { concatWith } from 'rxjs/operators';
import { a, b$, c$, d$, e$ } from 'helpers';
import { a$, b$, c$, d$, e$ } from 'helpers';

it('should support rest params', () => {
const arr = [b$, c$];
const o = of(a).pipe(concatWith(...arr)); // $ExpectType Observable<A | B | C>
const o2 = of(a).pipe(concatWith(d$, ...arr, e$)); // $ExpectType Observable<A | B | C | D | E>
const o = a$.pipe(concatWith(...arr)); // $ExpectType Observable<A | B | C>
const o2 = a$.pipe(concatWith(d$, ...arr, e$)); // $ExpectType Observable<A | B | C | D | E>
});

it('should infer correctly', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { observableMatcher } from '../helpers/observableMatcher';
declare function asDiagram(arg: string): Function;

/** @test {combineLatest} */
describe('combineLatest operator', () => {
describe('combineLatest', () => {
let testScheduler: TestScheduler;

beforeEach(() => {
Expand Down
Loading