为什么自定义管道在过滤 rxjs 后出现错误?
Why custom pipe has error after filter 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)),
),
),
);
}
为什么会出现此错误以及如何调整它?据我所知,我应该 return 在过滤器中观察到 requestTextLayerPipe
.
因为这里 filter((currentScale: number)
你接受 number
,但在第一个块中很明显 { x: number; y: number; }
是预期的
我收到这个错误:
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)),
),
),
);
}
为什么会出现此错误以及如何调整它?据我所知,我应该 return 在过滤器中观察到 requestTextLayerPipe
.
因为这里 filter((currentScale: number)
你接受 number
,但在第一个块中很明显 { x: number; y: number; }
是预期的