Skip to content

Need something more robust than polymorphic this typing for RxJS #5845

@benlesh

Description

@benlesh

I was pretty excited about this typing for RxJS, since it does have a sort of "fluent" style interface. However we have some issues with it that are discussed here: ReactiveX/rxjs#846

Basically, we have operators that return same-shaped, but different generic types:

map for example: Observable<T>.prototype.map<R>((value: T) => R): Observable<R>

The reason we were looking at this typing the above is that map doesn't always return an Observable, it could be called on a Subject which is a subclass of Observable. In that case, it actually returns a Subject, not an Observable, because of our fancy lift mechanism:

The Observable's lift:
https://github.com/ReactiveX/RxJS/blob/2896556afe8b663d4f983da1830fe407841e7d5b/src/Observable.ts#L51-L63

The Subject's lift:
https://github.com/ReactiveX/RxJS/blob/2896556afe8b663d4f983da1830fe407841e7d5b/src/Subject.ts#L37-L41

How lift is used (in map for example):
https://github.com/ReactiveX/RxJS/blob/2896556afe8b663d4f983da1830fe407841e7d5b/src/operators/map.ts#L17

It would be fantastic if we could provide our TypeScript users with the proper type information in their IDEs. Perhaps some additional syntax like this<R> would fit the bill? It's also worth noting that operators always return a new instance, rather than the same this instance, if that makes a difference.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DiscussionIssues which may not have code impactDuplicateAn existing issue was already createdNeeds ProposalThis issue needs a plan that clarifies the finer details of how it could be implemented.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions