Skip to content

Commit

Permalink
fix(pipe): replace rest parameters overload
Browse files Browse the repository at this point in the history
Replace the rest parameters overload with a signature that also includes
the A-I type parameters.

Closes ReactiveX#3841
  • Loading branch information
cartant committed Jul 25, 2018
1 parent eb77525 commit c0c5d0e
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/internal/Observable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ export class Observable<T> implements Subscribable<T> {
pipe<A, B, C, D, E, F, G>(op1: OperatorFunction<T, A>, op2: OperatorFunction<A, B>, op3: OperatorFunction<B, C>, op4: OperatorFunction<C, D>, op5: OperatorFunction<D, E>, op6: OperatorFunction<E, F>, op7: OperatorFunction<F, G>): Observable<G>;
pipe<A, B, C, D, E, F, G, H>(op1: OperatorFunction<T, A>, op2: OperatorFunction<A, B>, op3: OperatorFunction<B, C>, op4: OperatorFunction<C, D>, op5: OperatorFunction<D, E>, op6: OperatorFunction<E, F>, op7: OperatorFunction<F, G>, op8: OperatorFunction<G, H>): Observable<H>;
pipe<A, B, C, D, E, F, G, H, I>(op1: OperatorFunction<T, A>, op2: OperatorFunction<A, B>, op3: OperatorFunction<B, C>, op4: OperatorFunction<C, D>, op5: OperatorFunction<D, E>, op6: OperatorFunction<E, F>, op7: OperatorFunction<F, G>, op8: OperatorFunction<G, H>, op9: OperatorFunction<H, I>): Observable<I>;
pipe<R>(...operations: OperatorFunction<any, any>[]): Observable<R>;
pipe<A, B, C, D, E, F, G, H, I, R>(op1: OperatorFunction<T, A>, op2: OperatorFunction<A, B>, op3: OperatorFunction<B, C>, op4: OperatorFunction<C, D>, op5: OperatorFunction<D, E>, op6: OperatorFunction<E, F>, op7: OperatorFunction<F, G>, op8: OperatorFunction<G, H>, op9: OperatorFunction<H, I>, ...operations: OperatorFunction<any, any>[]): Observable<R>;
/* tslint:enable:max-line-length */

/**
Expand All @@ -318,7 +318,7 @@ export class Observable<T> implements Subscribable<T> {
* .subscribe(x => console.log(x))
* ```
*/
pipe<R>(...operations: OperatorFunction<T, R>[]): Observable<R> {
pipe<R>(...operations: OperatorFunction<any, any>[]): Observable<R> {
if (operations.length === 0) {
return this as any;
}
Expand Down
94 changes: 94 additions & 0 deletions type-specs/Observable-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import { of, OperatorFunction } from 'rxjs';
import { mapTo } from 'rxjs/operators';

function a<I extends string, O extends string>(input: I, output: O): OperatorFunction<I, O>;
function a<I, O extends string>(output: O): OperatorFunction<I, O>;
function a<I, O extends string>(inputOrOutput: I | O, output?: O): OperatorFunction<I, O> {
return mapTo<I, O>(output === undefined ? inputOrOutput as O : output);
}

describe('pipe', () => {
it('should infer for no arguments', () => {
const o = of('foo').pipe(); // $ExpectType Observable<string>
});

it('should infer for 1 argument', () => {
const o = of('foo').pipe(a('1')); // $ExpectType Observable<"1">
});

it('should infer for 2 arguments', () => {
const o = of('foo').pipe(a('1'), a('2')); // $ExpectType Observable<"2">
});

it('should infer for 3 arguments', () => {
const o = of('foo').pipe(a('1'), a('2'), a('3')); // $ExpectType Observable<"3">
});

it('should infer for 4 arguments', () => {
const o = of('foo').pipe(a('1'), a('2'), a('3'), a('4')); // $ExpectType Observable<"4">
});

it('should infer for 5 arguments', () => {
const o = of('foo').pipe(a('1'), a('2'), a('3'), a('4'), a('5')); // $ExpectType Observable<"5">
});

it('should infer for 6 arguments', () => {
const o = of('foo').pipe(a('1'), a('2'), a('3'), a('4'), a('5'), a('6')); // $ExpectType Observable<"6">
});

it('should infer for 7 arguments', () => {
const o = of('foo').pipe(a('1'), a('2'), a('3'), a('4'), a('5'), a('6'), a('7')); // $ExpectType Observable<"7">
});

it('should infer for 8 arguments', () => {
const o = of('foo').pipe(a('1'), a('2'), a('3'), a('4'), a('5'), a('6'), a('7'), a('8')); // $ExpectType Observable<"8">
});

it('should infer for 9 arguments', () => {
const o = of('foo').pipe(a('1'), a('2'), a('3'), a('4'), a('5'), a('6'), a('7'), a('8'), a('9')); // $ExpectType Observable<"9">
});

it('should infer {} for more than 9 arguments', () => {
const o = of('foo').pipe(a('1'), a('2'), a('3'), a('4'), a('5'), a('6'), a('7'), a('8'), a('9'), a('10')); // $ExpectType Observable<{}>
});

it('should enforce types for the 1st argument', () => {
const o = of('foo').pipe(a('#', '1')); // $ExpectError
});

it('should enforce types for the 2nd argument', () => {
const o = of('foo').pipe(a('1'), a('#', '2')); // $ExpectError
});

it('should enforce types for the 3rd argument', () => {
const o = of('foo').pipe(a('1'), a('2'), a('#', '3')); // $ExpectError
});

it('should enforce types for the 4th argument', () => {
const o = of('foo').pipe(a('1'), a('2'), a('3'), a('#', '4')); // $ExpectError
});

it('should enforce types for the 5th argument', () => {
const o = of('foo').pipe(a('1'), a('2'), a('3'), a('4'), a('#', '5')); // $ExpectError
});

it('should enforce types for the 6th argument', () => {
const o = of('foo').pipe(a('1'), a('2'), a('3'), a('4'), a('5'), a('#', '6')); // $ExpectError
});

it('should enforce types for the 7th argument', () => {
const o = of('foo').pipe(a('1'), a('2'), a('3'), a('4'), a('5'), a('6'), a('#', '7')); // $ExpectError
});

it('should enforce types for the 8th argument', () => {
const o = of('foo').pipe(a('1'), a('2'), a('3'), a('4'), a('5'), a('6'), a('7'), a('#', '8')); // $ExpectError
});

it('should enforce types for the 9th argument', () => {
const o = of('foo').pipe(a('1'), a('2'), a('3'), a('4'), a('5'), a('6'), a('7'), a('8'), a('#', '9')); // $ExpectError
});

it('should not enforce types beyond the 9th argument', () => {
const o = of('foo').pipe(a('1'), a('2'), a('3'), a('4'), a('5'), a('6'), a('7'), a('8'), a('9'), a('#', '10')); // $ExpectType Observable<{}>
});
});

0 comments on commit c0c5d0e

Please sign in to comment.