/** What `subscribe()` returns: call `unsubscribe()` to stop. */ export interface Unsubscribable { /** Stops the subscription and runs its teardown. */ unsubscribe(): void; } /** Stops a subscription. */ export type UnsubscribeFn = () => void; interface Subscribable { /** Starts the observable, sending what it emits to `observer`. */ subscribe(observer: Partial>): Unsubscribable; } /** * A stream of values, which starts when you subscribe to it. Links pass * results along as observables. * @see https://trpc.io/docs/client/links#creating-a-custom-link */ export interface Observable extends Subscribable< TValue, TError > { /** Returns an observable with the operators applied, in order. */ 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< TValue1, TError1, TValue2, TError2, TValue3, TError3, TValue4, TError4, TValue5, TError5, >( op1: OperatorFunction, op2: OperatorFunction, op3: OperatorFunction, op4: OperatorFunction, op5: OperatorFunction, ): Observable; } /** Gets an observable's values, its error, and its end. */ export interface Observer { /** Gets each value. */ next: (value: TValue) => void; /** Gets the error the observable ends with. */ error: (err: TError) => void; /** Called when the observable ends without an error. */ complete: () => void; } /** What the function passed to `observable()` returns to clean up on unsubscribe. */ export type TeardownLogic = // | SubscriptionLike Unsubscribable | UnsubscribeFn | void; /** A function of one argument. */ export type UnaryFunction = (source: TSource) => TReturn; /** Turns one observable into another, for `pipe()`. */ export type OperatorFunction< TValueBefore, TErrorBefore, TValueAfter, TErrorAfter, > = UnaryFunction< Subscribable, Subscribable >; /** An operator that keeps the value and error types. */ export type MonoTypeOperatorFunction = OperatorFunction< TValue, TError, TValue, TError >;