I have a need/desire to use more than six parameters in a forkJoin. Currently, based on the answer to another related question it doesn't appear possible to send more than 6 parameters to forkJoin.
However, based on the offical documentation, it says "forkJoin is an operator that takes any number of Observables which can be passed either as an array or directly as arguments."
forkJoin - Official Docs
Well, I'm doing that and I get an error TS2322:Type 'foo' is not assignable to type 'bar[]'.
In my research I've also found that it's best not to send the arguments as an array if you have promises that return different types, as that will type cast them to all the same type. - Source
Here's my code. I'm using the latest version of Typescript and Angular 4.
ngOnInit() {
this.spinner.show();
Observable.forkJoin(
this.loadParams(), // Returns an Observable<Object>
this.service.getPromiseType1(), // The rest return Observable<Array>
this.service.getPromiseType2(),
this.service.getPromiseType3(),
this.service.getPromiseType4(),
this.service.getPromiseType5(),
this.service.getPromiseType6(),
).finally(() => this.spinner.hide())
.subscribe(
([param, promise1, promise2, promise3, promise4, promise5, promise6]) => {
this.job = job;
this.value1 = promise1;
this.value2 = promise2;
this.value3 = promise3;
this.value4 = promise4;
this.value5 = promise5;
this.value6 = promise6;
}, (error) => {errorHandlingFunction}
});
If I remove any single parameter so that it's passing six parameters to forkJoin, it works fine. So my question is, in my case where I want to load the object observable and subsequent array observables all in one call, is there another way to do this? Is this a bug with forkJoin since the official documentation says it should be able to accept any number of Observables?
I've tried creating an Array of type Observable and using array.forEach() inside the forkJoin but it complains about returning type void. That seemed like a janky way of doing it anyhow.