JSON 在 Typescript 应用程序中找不到

JSON not found in Typescript application

我有一个简单的购买 class:

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

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