错误TS2339:类型“客户”上不存在属性“客户”

时间:2019-04-22 06:48:18

标签: angular rest

我试图为REST API创建一个接口,但标题中出现错误。我在控制台上附加了代码和图像。我将不胜感激。

 import { Customer } from '../components/hero/models/customer';
 
 getCustomerInfo(ndg: string): Observable<Customer> {
    const url = `${environment.apiUrl}${environment.ur3Path}cifCustomerDetails/customers/${ndg}`;
    return this.apiService.get(url);
  }

export interface Customer {
    name: string;
    surname: string;
    emails: Array<Emails>;
}

export interface Emails {
    address: string;
}

enter image description here

1 个答案:

答案 0 :(得分:1)

您的API响应似乎返回了一个包含电子邮件,姓名和姓氏字段的客户对象。

像这样修改您的界面:

    export interface Customer {
       customer : CustomerDetails;
    }

   export interface CustomerDetails{
        name: string;
        surname: string;
        emails: Array<Emails>;
   }

    export interface Emails {
        address: string;
    }