-
Notifications
You must be signed in to change notification settings - Fork 3k
Closed
Labels
TSIssues and PRs related purely to TypeScript issuesIssues and PRs related purely to TypeScript issuesbugConfirmed bugConfirmed bug
Description
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
import {
of,
Observable,
} from 'rxjs';
import {
tap,
mergeMap,
} from 'rxjs/operators';
export class Foo {
public foo1(): Observable<boolean> {
return of(true).pipe(
tap(), // 1
tap(), // 2
tap(), // 3
tap(), // 4
tap(), // 5
tap(), // 6
tap(), // 7
mergeMap(() => {
return of('');
}),
mergeMap(() => {
return of(true);
}),
);
}
public foo2(): Observable<boolean> {
return of(true).pipe(
tap(), // 1
tap(), // 2
tap(), // 3
tap(), // 4
tap(), // 5
tap(), // 6
tap(), // 7
tap(), // 8
mergeMap(() => {
return of('');
}),
mergeMap(() => {
return of(true);
}),
);
}
}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:
ERROR in index.ts(41,7): error TS2345: Argument of type 'OperatorFunction<boolean, string>' is not assignable to parameter of type 'OperatorFunction<boolean, boolean>'.
Type 'string' is not assignable to type 'boolean'.
Additional information:
The issue seems to be with Observable.ts, line 292, and mergeMap.ts, line 13:
pipe<R>(...operations: OperatorFunction<T, R>[]): Observable<R>;export function mergeMap<T, R>(project: (value: T, index: number) => ObservableInput<R>, concurrent?: number): OperatorFunction<T, R>;With more than 8 parameters, apparently all the OperatorFunction<T, R> need to return the same type .
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
TSIssues and PRs related purely to TypeScript issuesIssues and PRs related purely to TypeScript issuesbugConfirmed bugConfirmed bug