我该如何解决Typescript可订阅的界面错误?

问题描述 投票:1回答:1

我正在尝试将生产的Angular应用程序从7迁移到8。当我尝试构建时,出现以下错误:

ERROR in app/vehicle/vehicle.component.ts:90:36 - error TS2344: Type 'IOwnerVehicle' does not satisfy the constraint 'ObservableInput<any>'.
Property '[Symbol.iterator]' is missing in type 'IOwnerVehicle' but required in type 'Iterable<any>'.

90             flatMap<IVehicleOwner, IOwnerVehicle>(owner => {
                                      ~~~~~~~~~~~~~

  ../node_modules/typescript/lib/lib.es2015.iterable.d.ts:43:5
    43     [Symbol.iterator](): Iterator<T>;
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    '[Symbol.iterator]' is declared here.  

我相信我已经在RXJS Subscribable documentationTypeScript可预订接口问题]中找到了问题的根源。但是我仍然不知道如何解决这个问题。

VSCode显示车辆部件无错误。我认为ts文件后面的数字应该代表行和列,但是该组件只有50行,而第36行是空白。

可订阅的文档说了一些有关“ TypeScript在使用定义为符号属性的方法支持接口方面存在问题。”,但IOwnerVehicle接口只是一个属性包。它没有方法。

与订阅有关的唯一代码是构造函数

   constructor(@Inject(MAT_DIALOG_DATA) private owner: IVehicleOwner,
      private svc: SearchService,
      private searchDlg: MatDialogRef<OwnerVehicleComponent, IOwnerVehicle>) {
      this.svc.getOwnerVehicles(owner.id.toString()).subscribe(
         list => {
            if (list.length > 0)
               this.list = list;
            else
               this.searchFailed = true;
         });
   }

而且服务再简单不过了

   getOwnerVehicles(vehicleId: string): Observable<IOwnerVehicle[]> {
      const url = `${this.webApi}/vehicle`;
      return this.http.get<IOwnerVehicle[]>(url,
         {params: {owner : vehicleId}});
   }

有人可以帮我弄清楚我需要更改的内容或需要寻找的地方吗?

我正在尝试将生产Angular应用程序从7迁移到8。当我尝试构建时,出现以下错误:app / vehicle / vehicle.component.ts:90:36中的错误-错误TS2344:键入'。 。

angular typescript rxjs rxjs6
1个回答
0
投票

让我们看一下flatMap的类型:

© www.soinside.com 2019 - 2024. All rights reserved.