0

我有一个简单的采购类:

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。谁能告诉我如何解决这个问题?

4

1 回答 1

0

帮助我解决了我的问题。版本是 4.5.something。现在是 4.2.2,现在找到了 JSON。

于 2021-10-12T15:17:02.330 回答