Skip to content

Improve rest Generics in 3.0 RC sufficiently to support RxJS Observable.prototype.pipe #25660

Closed as not planned
@benlesh

Description

@benlesh

Search Terms

variadic pipe rxjs

Suggestion

Improve variadic kind support to allow determining the final part of the kind in some way. The problem is currently in 3.0-rc, I haven't found a way to improve RxJS's pipe method. There are a lot of people using TypeScript with RxJS and this has been a pain point for all of them.

Maybe some sort of syntax like:

declare type OperatorFunction<T, R> = (source: Observable<T>) => Observable<R>;

class Observable<T> {
  pipe<R, U extends [OperatorFunction<T, any>, ...OperatorFunction<any, any>[], OperatorFunction<any, R>]>(...operators: U): Observable<R>; 
}

It's a tricky case because type inferance also has to work.

Use Cases

RxJS currently has a lot of overloads just to support what is really a common functional programming feat.

Examples

Mostly I'd use this as shown above to define the pipe method on Observable.

Really I'm looking for any solution to this problem though. It's a very common complaint from our TypeScript users.

🙏

Checklist

My suggestion meets these guidelines:

  • This wouldn't be a breaking change in existing TypeScript / JavaScript code
  • This wouldn't change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn't a runtime feature (e.g. new expression-level syntax)

Metadata

Metadata

Assignees

No one assigned

    Labels

    SuggestionAn idea for TypeScriptToo ComplexAn issue which adding support for may be too complex for the value it adds

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions