-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mixed types in pipes with mergeMap and more than 8 parameters yield typescript error #3766
Comments
That particular signature for pipe<R>(...operations: OperatorFunction<any, any>[]): Observable<R>; as there's no way each operator can take an observable of type |
Ok, the code would need to change to the below - but with the current signature for pipe the typescript compilation fails nonetheless. public foo2(): Observable<boolean> {
return of(true).pipe<boolean>(
tap(), // 1
tap(), // 2
tap(), // 3
tap(), // 4
tap(), // 5
tap(), // 6
tap(), // 7
tap(), // 8
mergeMap(() => {
return of('');
}),
mergeMap(() => {
return of(true);
}),
);
} |
The current signature for |
Labeling this as a bug, just because of this comment |
This overload on pipe: pipe<R>(...operations: OperatorFunction<any, any>[]): Observable<R>; causes type checking to break because: Observable<T> o1;
Observable<string> o2 = o2.pipe(map((x : X) => x + '')); type checks, though it shouldn't. (It matches that overload.) (I noticed that in version 6.2.2) I'm very new to rxjs and typescript too, but it would seem that the only the correct type for I've seen some other bugs here that people complain about using the spread operator with pipe, eg, like As for the case in this bug, more than eight operations explicitly passed, I'd just recommend chaining or using the static pipe: o.pipe(o1, o2, o3, o4).pipe(o5, o6, o7, o8, o9)
// or
o.pipe(pipe(o1, o2, o3, o4), pipe(o5, o6, o7, o8, o9)) It might be a drag to not have the |
@kjmcclain Your comment - and this issue itself - should have been addressed by #3945, which has been merged, but there isn't yet a release that includes the change. |
Awesome, thanks! I tried searching for an open issue about this, but I couldn't find it. |
In the below code, foo1() is ok, but foo2() is not. In other words, in pipes with more than 8 parameters in the stream, the type definition assumes that all the observables of the stream return the same types.
RxJS version:
6.2.0
Code to reproduce:
Stackblitz: https://stackblitz.com/edit/typescript-e8dcm5?file=index.ts
Expected behavior:
No typescript compilation error, as mergeMap should be able to change the type of the Observable, and only the last mergeMap should be relevant for the resulting type.
Actual behavior:
Additional information:
The issue seems to be with Observable.ts, line 292, and mergeMap.ts, line 13:
With more than 8 parameters, apparently all the OperatorFunction<T, R> need to return the same type .
The text was updated successfully, but these errors were encountered: