combineLatest throws TS2349 with 6 or more streams
This is true, maximum number of source Observables is 6, see https://github.com/ReactiveX/rxjs/blob/master/src/internal/observable/combineLatest.ts#L68.
However, The only reason is that it's unlikely to have so many inputs so there are no function overloads defined for that. This still doesn't restrict you from combining multiple combineLatest
s:
combineLatest([
combineLatest([s1, s2, ...]),
combineLatest([s7, s8, ...]),
]).pipe(
map(([results1, results2]) => [...results1, ...results2]),
);
Btw, this is a TypeScript error that you should be able to suppress with @ts-ignore
(even though you might miss other TypeScript errors later):
// @ts-ignore
plans$ = combineLatest([
this.planService.getPlans(),
this.databaseService.getSpecieses(),
...
this.databaseService.getAnalysises(),
])
This way losing types:
combineLatest([
combineLatest([s1, s2, ...]),
combineLatest([s7, s8, ...]),
]).pipe(
map(([results1, results2]) => [...results1, ...results2]),
);
I didnt found the way to save it except this:
combineLatest([
combineLatest([A, B, C]),
combineLatest([D, E, F]),
combineLatest([G]),
]).pipe(
map(([r1, r2, r3]) => {
return [...r1, ...r2, ...r3] as [
typeof r1[0],
typeof r1[1],
typeof r1[2],
typeof r2[0],
typeof r2[1],
typeof r2[2],
typeof r3[0],
];
}))
Just for the sake of completeness (and having all the answer available on stackoverflow, and not in some link), the solution from the issue Balu linked is simply declaring the types each observable will emit:
combineLatest<any>(a$, b$, c$, d$, e$, f$).pipe(
// Manually typed arguments below :(
map(([a, b, c, d, e, f]: [string, number, string, Foo, Bar, Baz]) => doStuff(a, b, c, d, e, f))
)
This can be greatly simplified by defining a new Type with the expected param types.
export type CombinedSources = [string, number, string, Foo, Bar, Baz];
combineLatest<any>(a$, b$, c$, d$, e$, f$).pipe(
map(([a, b, c, d, e, f]: CombinedSources) => doStuff(a, b, c, d, e, f))
)