当超过6个参数时,Observable.forkJoin返回错误的类型 [英] Observable.forkJoin wrong return type when more than 6 arguments

查看:98
本文介绍了当超过6个参数时,Observable.forkJoin返回错误的类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Observable.forkJoin遇到一个问题,即推断错误的返回类型,然后在我传递六个以上的参数时导致错误.

I have an issue with Observable.forkJoin inferring the wrong return type and then causing errors when I pass more than 6 arguments.

Observable.forkJoin(service.getType1, service.getType2, service.getType3 ...)
        .subscribe(x => {
            this.type1Arr = x[0];
            this.type2Arr = x[1];
            this.type3Arr = x[2];

服务中的每个函数调用均返回 Observable< Array< type>> .当我从传入的服务中收到6个以上的调用时,编译器确定返回应该为 Type1 [] [] .尽管它可以正常工作至6个,但返回的正确,我可以分配强类型的结果.

Each function call from the service returns an Observable<Array<type>>. The compiler is determining that the return should be Type1[][] when I have more than 6 calls from the service passed in. It works fine up to 6 though, it will have the correct return and I can assign strongly typed results.

我正在使用rxjs 5.4.3和Typescript 2.4.0(用于Visual Studio的Typescript工具是2.5.2).

I'm using rxjs 5.4.3 and Typescript 2.4.0 (Typescript Tools for Visual Studio is 2.5.2).

有没有解决方法而无需强制转换吗?

Is there a workaround for this without casting it?

推荐答案

forkJoin 的类型定义最大的 forkJoin 具有6个参数,如下所示: https://github.com/ReactiveX/rxjs/blob/master/src/observable/ForkJoinObservable.ts#L27

The typings for forkJoin define max forkJoin with 6 parameters as you can see here: https://github.com/ReactiveX/rxjs/blob/master/src/observable/ForkJoinObservable.ts#L27

请注意,可以使用多种方法来调用具有6个以上参数的 forkJoin :

Note that there are different ways to call forkJoin with more than 6 parameters:

Observable.forkJoin(observables)

Observable.forkJoin(...observables)

您还可以强制返回类型( https://github.com/ReactiveX/rxjs/blob/master/src/observable/ForkJoinObservable.ts#L35 ):

You can also force return types (https://github.com/ReactiveX/rxjs/blob/master/src/observable/ForkJoinObservable.ts#L35):

Observable.forkJoin<Whatever[]>(observables)

这篇关于当超过6个参数时,Observable.forkJoin返回错误的类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆