From 717cadf140afbef6ee8ee178700c19337eded687 Mon Sep 17 00:00:00 2001 From: Peter Laffey Date: Tue, 24 Jul 2018 13:31:03 -0500 Subject: [PATCH] fix(Observable): correct typings issues in pipe Allows specific types of Observables to be passed through (as in #2972), and also prevents incorrect typings from falling through to ellipsis function due to the use of `any`. Closes #2972 --- src/internal/Observable.ts | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/internal/Observable.ts b/src/internal/Observable.ts index a60bcf8391..81f233d1e9 100644 --- a/src/internal/Observable.ts +++ b/src/internal/Observable.ts @@ -1,7 +1,7 @@ import { Operator } from './Operator'; import { Subscriber } from './Subscriber'; import { Subscription } from './Subscription'; -import { TeardownLogic, OperatorFunction, PartialObserver, Subscribable } from './types'; +import { TeardownLogic, PartialObserver, Subscribable, UnaryFunction } from './types'; import { toSubscriber } from './util/toSubscriber'; import { iif } from './observable/iif'; import { throwError } from './observable/throwError'; @@ -287,16 +287,16 @@ export class Observable implements Subscribable { /* tslint:disable:max-line-length */ pipe(): Observable; - pipe(op1: OperatorFunction): Observable; - pipe(op1: OperatorFunction, op2: OperatorFunction): Observable; - pipe(op1: OperatorFunction, op2: OperatorFunction, op3: OperatorFunction): Observable; - pipe(op1: OperatorFunction, op2: OperatorFunction, op3: OperatorFunction, op4: OperatorFunction): Observable; - pipe(op1: OperatorFunction, op2: OperatorFunction, op3: OperatorFunction, op4: OperatorFunction, op5: OperatorFunction): Observable; - pipe(op1: OperatorFunction, op2: OperatorFunction, op3: OperatorFunction, op4: OperatorFunction, op5: OperatorFunction, op6: OperatorFunction): Observable; - pipe(op1: OperatorFunction, op2: OperatorFunction, op3: OperatorFunction, op4: OperatorFunction, op5: OperatorFunction, op6: OperatorFunction, op7: OperatorFunction): Observable; - pipe(op1: OperatorFunction, op2: OperatorFunction, op3: OperatorFunction, op4: OperatorFunction, op5: OperatorFunction, op6: OperatorFunction, op7: OperatorFunction, op8: OperatorFunction): Observable; - pipe(op1: OperatorFunction, op2: OperatorFunction, op3: OperatorFunction, op4: OperatorFunction, op5: OperatorFunction, op6: OperatorFunction, op7: OperatorFunction, op8: OperatorFunction, op9: OperatorFunction): Observable; - pipe(...operations: OperatorFunction[]): Observable; + pipe(op1: UnaryFunction, A>): A; + pipe(op1: UnaryFunction, A>, op2: UnaryFunction): B; + pipe(op1: UnaryFunction, A>, op2: UnaryFunction, op3: UnaryFunction): C; + pipe(op1: UnaryFunction, A>, op2: UnaryFunction, op3: UnaryFunction, op4: UnaryFunction): D; + pipe(op1: UnaryFunction, A>, op2: UnaryFunction, op3: UnaryFunction, op4: UnaryFunction, op5: UnaryFunction): E; + pipe(op1: UnaryFunction, A>, op2: UnaryFunction, op3: UnaryFunction, op4: UnaryFunction, op5: UnaryFunction, op6: UnaryFunction): F; + pipe(op1: UnaryFunction, A>, op2: UnaryFunction, op3: UnaryFunction, op4: UnaryFunction, op5: UnaryFunction, op6: UnaryFunction, op7: UnaryFunction): G; + pipe(op1: UnaryFunction, A>, op2: UnaryFunction, op3: UnaryFunction, op4: UnaryFunction, op5: UnaryFunction, op6: UnaryFunction, op7: UnaryFunction, op8: UnaryFunction): H; + pipe(op1: UnaryFunction, A>, op2: UnaryFunction, op3: UnaryFunction, op4: UnaryFunction, op5: UnaryFunction, op6: UnaryFunction, op7: UnaryFunction, op8: UnaryFunction, op9: UnaryFunction): I; + pipe(op1: UnaryFunction, A>, op2: UnaryFunction, op3: UnaryFunction, op4: UnaryFunction, op5: UnaryFunction, op6: UnaryFunction, op7: UnaryFunction, op8: UnaryFunction, op9: UnaryFunction, ...operations: UnaryFunction[]): R; /* tslint:enable:max-line-length */ /** @@ -318,7 +318,7 @@ export class Observable implements Subscribable { * .subscribe(x => console.log(x)) * ``` */ - pipe(...operations: OperatorFunction[]): Observable { + pipe(...operations: UnaryFunction, R>[]): R { if (operations.length === 0) { return this as any; }