Angular 5.2错误:无法将类型'Observable <something []>转换为'Observable <somethingelse>'

时间:2018-04-18 13:49:10

标签: angular typescript

使用Angular 5.2,我收到此resharper打字稿错误: 无法转换类型'Observable&lt; IPartBundle []&gt;输入'Observable&lt; IOrderHead&gt;'

public orderHead$: Observable<IOrderHead>;

ngOnInit() {

    this.orderHead$ = this.route.paramMap.switchMap((params: ParamMap) => {
        this.partBundle$ = this.orderShipService.getPartBundleObservable(this.orderShipDetails$, this.cartons$, this.licensePlate, this.orderLine);
        return this.order.getOrderHeadObservable(+params.get('orderNumber'));
    }).share();
}

1 个答案:

答案 0 :(得分:0)

似乎Resharper想要包含在share方法中的类型,就像这样。

this.orderHead$ = this.route.paramMap.switchMap((params: ParamMap) => {
    this.partBundle$ = 
this.orderShipService.getPartBundleObservable(this.orderShipDetails$, 
this.cartons$, this.licensePlate, this.orderLine);
    return this.order.getOrderHeadObservable(+params.get('orderNumber'));
}).share<IOrderHead>();

然后,resharper错误就消失了。