我有一个简单的采购类:
export class Purchase {
customer!: Customer;
shippingAddress!: Address;
billingAddress!: Address;
order!: Order;
orderItems!: OrderItem[];
}
我有一个结帐组件,它执行以下操作:
// populate purchase - customer
purchase.customer = this.checkoutFormGroup.controls['customer'].value;
// populate purchase - shipping address
purchase.shippingAddress = this.checkoutFormGroup.controls['shippingAddress'].value;
const shippingState: State = JSON.parse(JSON.stringify(purchase.shippingAddress.state));
const shippingCountry: Country = JSON.parse(JSON.stringify(purchase.shippingAddress.country));
purchase.shippingAddress.state = shippingState.name;
purchase.shippingAddress.country = shippingCountry.name;
在此下面的行给出了错误Cannot find name 'JSON'.ts(2304)
:
const shippingState: State = JSON.parse(JSON.stringify(purchase.shippingAddress.state));
const shippingCountry: Country = JSON.parse(JSON.stringify(purchase.shippingAddress.country));
我怀疑问题是我有以下配置tsconfig.json
:
"compilerOptions": {
...
"target": "es2017",
"module": "es2020",
"lib": [
"es2018",
"dom"
]
}
我尝试更改es2018
为,es5
但这并没有解决我的问题。无论哪种方式,肯定应该有一种方法来做这种事情es2018
。谁能告诉我如何解决这个问题?