-
Notifications
You must be signed in to change notification settings - Fork 13k
Description
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.