From 312386b252581389bc0bbdc0da6ce508ab9e8aef Mon Sep 17 00:00:00 2001 From: Peter Laffey Date: Tue, 24 Jul 2018 13:22:31 -0500 Subject: [PATCH] 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`. --- src/internal/Observable.ts | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/internal/Observable.ts b/src/internal/Observable.ts index a60bcf8391..e2b71bae19 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, OperatorFunction, PartialObserver, Subscribable, UnaryFunction } from './types'; import { toSubscriber } from './util/toSubscriber'; import { iif } from './observable/iif'; import { throwError } from './observable/throwError'; @@ -189,8 +189,8 @@ export class Observable implements Subscribable { * @method subscribe */ subscribe(observerOrNext?: PartialObserver | ((value: T) => void), - error?: (error: any) => void, - complete?: () => void): Subscription { + error?: (error: any) => void, + complete?: () => void): Subscription { const { operator } = this; const sink = toSubscriber(observerOrNext, error, complete); @@ -200,8 +200,8 @@ export class Observable implements Subscribable { } else { sink.add( this.source || (config.useDeprecatedSynchronousErrorHandling && !sink.syncErrorThrowable) ? - this._subscribe(sink) : - this._trySubscribe(sink) + this._subscribe(sink) : + this._trySubscribe(sink) ); } @@ -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 */ /**