【问题标题】:Why custom pipe has error after filter rxjs?为什么过滤rxjs后自定义管道有错误?
【发布时间】:2021-06-26 07:17:06
【问题描述】:

我收到此错误:

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

【问题讨论】:

    标签: angular rxjs rxjs6


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2021-11-15
      • 2020-07-01
      • 2016-02-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多