属性'address'在类型 'string' 上不存在



嘿,我正在将对象从一个页面传递到另一个页面&试图在另一页中存储对象,但在此期间遇到错误。Es Lint错误。

accountData:any={
name:this.tenantAccount.name,
telephone_number:this.tenantAccount.telephone_number,
mobile_number:this.tenantAccount.owner.mobile_number,
address:this.tenantAccount.address.address,
owner_name:this.tenantAccount.owner.name,
tenant_email:this.tenantAccount.tenant_email,
created_by:this.tenantAccount.created_by.name,
source_name:this.tenantAccount.source.name,
latitude:this.tenantAccount.address.latitude,
longitude:this.tenantAccount.address.longitude,
state:this.tenantAccount.address.state.name
}

上面的代码存储。这是因为Typescript

为什么会发生&最好的解决办法是什么

根据错误Property 'address' does not exist on type 'string',this.tenantAccount.address是字符串类型,但根据您的代码,您将其视为对象,并试图从它访问address属性,这是不正确的,根据错误

我认为应该是this.tenantAccount.address ✅而不是this.tenantAccount.address.address ❌

相关内容

最新更新