繁体   English   中英

类方法的扩展通用参数不构建

[英]Extended generic parameter of class method dont build

我在用ng build构建一个有角度的项目时遇到问题。

public update (item: T extends IModel): Observable<T> {
  return this.http.put<any>(`${this.api}/${this.resource}/${item.id}`, item);
}

它说,它期望在(item: T extends IModel)使用','。

任何想法如何使它建立? 它与ng serve搭配效果很好,对我来说看起来很正确。

您需要像这样声明类型参数:

public update<T extends IModel>(item: T): Observable<T> {
  return this.http.put<any>(`${this.api}/${this.resource}/${item.id}`, item);
}

谢谢

我刚刚找到了方法。 我做了什么:

export class ResourceService<T extends IModel> {
   ...

  public update (item: T): Observable<T> {
    return this.http.put<any>(`${this.api}/${this.resource}/${item.id}`, item);
  }
}

我的界面是:

 export interface IModel {
  id: string;
 }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM