-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: support N args in static race and ensure observable returned (#5286
) * test: add failing test for race * fix: use from on ObservableInput * fix: support N args for static race * chore: use dtslint helpers
- Loading branch information
Showing
3 changed files
with
32 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,120 +1,32 @@ | ||
import { race, of } from 'rxjs'; | ||
|
||
it('should infer correctly with 1 parameter', () => { | ||
const a = of(1); | ||
const o = race(a); // $ExpectType Observable<number> | ||
}); | ||
import { a$, b, b$, c, c$, d$, e$, f$ } from '../helpers'; | ||
|
||
describe('race(a, b, c)', () => { | ||
it('should infer correctly with multiple parameters of the same type', () => { | ||
const a = of(1); | ||
const b = of(2); | ||
const o = race(a, b); // $ExpectType Observable<number> | ||
}); | ||
|
||
it('should support 2 parameters with different types', () => { | ||
const a = of(1); | ||
const b = of('a'); | ||
const o = race(a, b); // $ExpectType Observable<string | number> | ||
}); | ||
|
||
it('should support 3 parameters with different types', () => { | ||
const a = of(1); | ||
const b = of('a'); | ||
const c = of(true); | ||
const o = race(a, b, c); // $ExpectType Observable<string | number | boolean> | ||
}); | ||
|
||
it('should support 4 parameters with different types', () => { | ||
const a = of(1); | ||
const b = of('a'); | ||
const c = of(true); | ||
const d = of([1, 2, 3]); | ||
const o = race(a, b, c, d); // $ExpectType Observable<string | number | boolean | number[]> | ||
}); | ||
|
||
it('should support 5 parameters with different types', () => { | ||
const a = of(1); | ||
const b = of('a'); | ||
const c = of(true); | ||
const d = of([1, 2, 3]); | ||
const e = of(['blah']); | ||
const o = race(a, b, c, d, e); // $ExpectType Observable<string | number | boolean | number[] | string[]> | ||
}); | ||
|
||
it('should support 6 or more parameters of the same type', () => { | ||
const a = of(1); | ||
const o = race(a, a, a, a, a, a, a, a, a, a, a, a, a, a); // $ExpectType Observable<number> | ||
}); | ||
|
||
it('should return unknown for 6 or more arguments of different types', () => { | ||
const a = of(1); | ||
const b = of('a'); | ||
const c = of(true); | ||
const d = of([1, 2, 3]); | ||
const e = of(['blah']); | ||
const f = of({ foo: 'bar' }); | ||
const o = race(a, b, c, d, e, f); // $ExpectType Observable<unknown> | ||
it('should support N arguments of different types', () => { | ||
const o1 = race(a$); // $ExpectType Observable<A> | ||
const o2 = race(a$, b$); // $ExpectType Observable<A | B> | ||
const o3 = race(a$, b$, c$); // $ExpectType Observable<A | B | C> | ||
const o4 = race(a$, b$, c$, d$); // $ExpectType Observable<A | B | C | D> | ||
const o5 = race(a$, b$, c$, d$, e$); // $ExpectType Observable<A | B | C | D | E> | ||
const o6 = race(a$, b$, c$, d$, e$, f$); // $ExpectType Observable<A | B | C | D | E | F> | ||
}); | ||
}); | ||
|
||
describe('race([a, b, c])', () => { | ||
it('should infer correctly with multiple parameters of the same type', () => { | ||
const a = of(1); | ||
const b = of(2); | ||
const o = race([a, b]); // $ExpectType Observable<number> | ||
}); | ||
|
||
it('should support 2 parameters with different types', () => { | ||
const a = of(1); | ||
const b = of('a'); | ||
const o = race([a, b]); // $ExpectType Observable<string | number> | ||
}); | ||
|
||
it('should support 3 parameters with different types', () => { | ||
const a = of(1); | ||
const b = of('a'); | ||
const c = of(true); | ||
const o = race([a, b, c]); // $ExpectType Observable<string | number | boolean> | ||
}); | ||
|
||
it('should support 4 parameters with different types', () => { | ||
const a = of(1); | ||
const b = of('a'); | ||
const c = of(true); | ||
const d = of([1, 2, 3]); | ||
const o = race([a, b, c, d]); // $ExpectType Observable<string | number | boolean | number[]> | ||
}); | ||
|
||
it('should support 5 parameters with different types', () => { | ||
const a = of(1); | ||
const b = of('a'); | ||
const c = of(true); | ||
const d = of([1, 2, 3]); | ||
const e = of(['blah']); | ||
const o = race([a, b, c, d, e]); // $ExpectType Observable<string | number | boolean | number[] | string[]> | ||
}); | ||
|
||
it('should support 6 or more parameters of the same type', () => { | ||
const a = of(1); | ||
const o = race([a, a, a, a, a, a, a, a, a, a, a, a, a, a]); // $ExpectType Observable<number> | ||
}); | ||
|
||
it('should return {} for 6 or more arguments of different types', () => { | ||
const a = of(1); | ||
const b = of('a'); | ||
const c = of(true); | ||
const d = of([1, 2, 3]); | ||
const e = of(['blah']); | ||
const f = of({ foo: 'bar' }); | ||
const o = race([a, b, c, d, e, f]); // $ExpectType Observable<unknown> | ||
it('should support N arguments of different types', () => { | ||
const o1 = race([a$]); // $ExpectType Observable<A> | ||
const o2 = race([a$, b$]); // $ExpectType Observable<A | B> | ||
const o3 = race([a$, b$, c$]); // $ExpectType Observable<A | B | C> | ||
const o4 = race([a$, b$, c$, d$]); // $ExpectType Observable<A | B | C | D> | ||
const o5 = race([a$, b$, c$, d$, e$]); // $ExpectType Observable<A | B | C | D | E> | ||
const o6 = race([a$, b$, c$, d$, e$, f$]); // $ExpectType Observable<A | B | C | D | E | F> | ||
}); | ||
}); | ||
|
||
it('should race observable inputs', () => { | ||
const o = race(of(1), Promise.resolve('foo'), [true, false]); // $ExpectType Observable<string | number | boolean> | ||
const o = race(a$, Promise.resolve(b), [c]); // $ExpectType Observable<A | B | C> | ||
}); | ||
|
||
it('should race an array observable inputs', () => { | ||
const o = race([of(1), Promise.resolve('foo'), [true, false]]); // $ExpectType Observable<string | number | boolean> | ||
const o = race([a$, Promise.resolve(b), [c]]); // $ExpectType Observable<A | B | C> | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters