Javascript 类型';基本响应<;IAAvailableParameters[]和gt';类型';中缺少以下属性;IavailableParameters[]和#x27;:长度、流行音乐等

Javascript 类型';基本响应<;IAAvailableParameters[]和gt';类型';中缺少以下属性;IavailableParameters[]和#x27;:长度、流行音乐等,javascript,angular,typescript,api,observable,Javascript,Angular,Typescript,Api,Observable,我正在对API进行get调用,并返回一个对象列表。然后,我将该数据分配给我的DataService中的一个属性,以便可以跨组件使用它 以下是我的组件中调用服务的代码: getAvailableParameters() { this.verificationService.getAvailableParameters(this.itemNumbers).subscribe((res => { this.dataService.availableParameters

我正在对API进行get调用,并返回一个对象列表。然后,我将该数据分配给我的DataService中的一个属性,以便可以跨组件使用它

以下是我的组件中调用服务的代码:

  getAvailableParameters() {
     this.verificationService.getAvailableParameters(this.itemNumbers).subscribe((res => {
      this.dataService.availableParameters = res;
    }))}
下面是对API的调用

  getAvailableParameters(itemNumbers: string[]){
    return this.http.get<BaseResponse<IavailableParameters[]>>(`${this.baseUrl}api/verification/${itemNumbers}`)
  }
如您所见,从API返回的对象也包装在BaseResponse对象中(我认为这是问题所在,但不知道如何解决),定义如下:

import { Error } from './Error'

export interface BaseResponse<T> {
    isSuccessful: boolean,

    error: Error;

    results: T;
}
从“./Error”导入{Error}
导出接口BaseResponse{
isSuccessful:布尔值,
错误:错误;
结果:T;
}
这正是我得到的错误:

    ERROR in src/app/Components/verification-reply/verification-reply.component.ts(28,7): error TS2740: Type 'BaseResponse<IavailableParameters[]>' is missing the following properties from type 'IavailableParameters[]': length, pop, push, concat, and 26 more.
src/app/Components/verification reply/verification reply.component.ts(28,7)中出现错误:错误TS2740:类型“BaseResponse”缺少类型“IavailableParameters[]”中的以下属性:长度、弹出、推送、concat等。
当我删除基响应类型时,它工作正常,因为我假设它没有将其注册为数组或其他东西。当我返回的对象不是数组时,数据服务对象的绑定方法工作得很好

我在这方面缺乏经验,需要一些帮助来解决这个错误

当我删除基响应类型时,它工作正常,因为我假设它没有将其注册为数组或其他东西

这是意料之中的,因为
BaseResponse
不是数组。它是一个
对象
,具有属性
isSuccessful
error
results
。属性
results
是一个数组
iaavailableparameters[]

您需要确保向
this.http.get
提供的任何类型都与请求返回的实际类型匹配。它是一个
iaavailableparameters
数组吗?或者对象具有
isSuccessful
error
results


如果您有一个类型为
BaseResponse
的变量
response
,并且您试图将其用作数组
IavailableParameters[]
,就像您发布的错误消息中那样,那么只需使用
response.results
,而不是整个response对象。

正如Lindas评论所建议的,“results”基本响应上的对象包含我要查找的实际对象。我需要获取res.results,而不是映射res=>IavailableParameters。
    ERROR in src/app/Components/verification-reply/verification-reply.component.ts(28,7): error TS2740: Type 'BaseResponse<IavailableParameters[]>' is missing the following properties from type 'IavailableParameters[]': length, pop, push, concat, and 26 more.