简体   繁体   English

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

[英]Extended generic parameter of class method dont build

I got an issue while building an angular project with ng build . 我在用ng build构建一个有角度的项目时遇到问题。

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

It say, it expect a ',' in (item: T extends IModel) . 它说,它期望在(item: T extends IModel)使用','。

Any idea how to make it build? 任何想法如何使它建立? It works well with ng serve and to looks correct to me. 它与ng serve搭配效果很好,对我来说看起来很正确。

You need to declare the type parameter like this: 您需要像这样声明类型参数:

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

Thanks 谢谢

I just found a way. 我刚刚找到了方法。 What i have done: 我做了什么:

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

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

My interface is: 我的界面是:

 export interface IModel {
  id: string;
 }

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

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