类型 'Observable<Object>' 不可分配给类型 'Observable<Product>'

Type 'Observable<Object>' is not assignable to type 'Observable<Product>'

我在服务中遇到了这个问题:Type Observable 'Object' is not assignable to type Observable 'Product.你知道如何解决吗? 这是我的 class

export class Product{
  public id:number;
  public price:number;
}

我的学生:

onSaveProduct(data: any) {
    this.catService.saveResource(this.catService.host+"/produits",data)
      .subscribe(res=>{
        this.currentProduct=res
      },err=>{
        console.log(err)
      })
  }

我的服务:

public saveResource(url,data):Observable<Product>{
    return this.httpClient.post(url,data);
  }

您需要在 post 调用自身中包含 Observable

public saveResource(url,data):Observable<Product>{
    return this.httpClient.post<Product>(url,data);
}