首页 > 解决方案 > 为什么过滤rxjs后自定义管道有错误?

问题描述

我收到此错误:

Argument of type 'UnaryFunction<Observable<number>, Observable<any>>' is not assignable to parameter of type 'OperatorFunction<{ x: number; y: number; }, any>'

在线上:

  this.Map.moveMap$
            .pipe(
                filter((v) => v.x !== 0 || v.y !== 0),
                this.requestTextLayerPipe(),
            )
            .subscribe();

requestTextLayerPipe自定义管道在哪里:

private requestTextLayerPipe() {
    return pipe(
        filter((currentScale: number) => currentScale <= this.scaleLimitTextLayer.max || currentScale >= this.scaleLimitTextLayer.min),
        map(() => this.getTextLayersId()),
        filter((dispar: string[]) => dispar.length > 0),
        map((dispar: string[]) => this.getTextLayerProps(dispar)),
        switchMap((props: RequestTextLayerProps) =>
            this.Map.httpClient
                .get(this.buildUrlRequestTextLayer(props), {
                    observe: 'body',
                    responseType: 'blob',
                })
                .pipe(
                    map((response) => {
                        return { props, response };
                    }),
                    catchError((error) => of(error)),
                ),
        ),
    );
}

为什么我会收到此错误以及如何适应它?正如我所得到的,我应该将过滤器中的 observable 返回到requestTextLayerPipe.

标签: angularrxjsrxjs6

解决方案


因为在这里filter((currentScale: number)你接受number,但在第一个块中很明显这{ x: number; y: number; }是预期的


推荐阅读