No JSON data detected in Typescript application

My Purchase class is fairly simple:

export class Purchase {
    customer!: Customer;
    shippingAddress!: Address;
    billingAddress!: Address;
    order!: Order;
    orderItems!: OrderItem[];
}

I have a checkout component that performs the following actions:

// 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;

The code snippet below throws an error 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));

I suspect the issue may stem from my configuration in tsconfig.json:

"compilerOptions": {
    ...
    "target": "es2017",
    "module": "es2020",
    "lib": [
      "es2018",
      "dom"
    ]
}

I attempted changing es2018 to es5 without resolving the issue. Is there a solution within the realm of es2018? Any advice on how to rectify this matter would be appreciated.

Answer №1

I found a solution here that resolved the problem I was facing. The previous version was 4.5.x but now it's 4.2.2 and JSON is working correctly.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

If you're trying to work with this file type, you might require a suitable loader. Make sure you

Attempting to utilize Typescript typings for the Youtube Data API found at: https://github.com/Bolisov/typings-gapi/tree/master/gapi.client.youtube-v3 Within the Ionic framework, an error is encountered after running 'Ionic Serve' with the follo ...

Exploring the crossroads of MongoDB, Mongoose, and Node.js: An in-depth look

Searching for ways to retrieve references in MongoDB using Node.js and Mongoose. After reading the documentation, I discovered that there are two options available: Manual References or DBRefs. Given that Manual References are recommended, I proceeded to ...

Encountered GL_ERROR while rendering a model loaded from a gltf file

Having trouble with loading a gltf model, currently when loaded it appears entirely black and I'm receiving the following error message in my console: [.WebGL-0x7f8f03050e00]GL ERROR :GL_INVALID_ENUM : glTexParameteri: param was GL_CLOSE_PATH_NV Thi ...

Encountering the "React Hook useEffect missing dependency" warning for a state variable that does not actually need to be included in the dependency array

My eslint is throwing an error for react-hooks/exhaustive-deps. I believe my code is correct as the function should only execute when there is a change in the pathname: const pathname = usePathname(); useEffect(() => { setNavigation( navig ...

What is the best way to extract ABC 12005 from strings like ABC000012005 and ABC0000012005?

My task involves parsing a string with values like ABC000012005,ABC0000012005. The desired output is to extract the prefix and numbers without leading zeros, formatted as ABC 12005, ABC 12005 ...

Is QA supported by LG WebOS 3.5 through webdriver?

I've been experimenting with Javascript ( nodejs ) and have successfully automated browser operations using selenium-webdriver on a local server. However, I am facing challenges when trying to automate tasks on my LG WebOS 3.5 TV. Does anyone know how ...

The Jquery Countdown plugin fails to initialize

Currently struggling with getting the jquery Countdown plugin to work for a 12-day countdown. Despite all efforts, the countdown does not seem to start and I am at a loss on how to troubleshoot this issue. After searching online extensively, I have yet to ...

The "void" type cannot be assigned to the type "ObservableInput<{}>"

I recently encountered this issue after updating to TS 2.2.2, and I suspect that is the root cause... While the code still functions properly, I am now seeing this error. I attempted various solutions such as returning an empty observable, catching the re- ...

Can Chrome DevTools be used to manipulate the login process?

For a recent project, I utilized the login authentication logic from this GitHub repository as a reference: https://github.com/cornflourblue/angular-authentication-example In a situation where the backend was offline, I manually tweaked the frontend code ...

Verify whether ngOnDestroy gets invoked when transitioning between routes

One of the challenges I am faced with is dealing with a child form component that is created within material tabs: <md-tab *ngFor="let selectedEntity of selectedEntities; let i=index"> <template md-tab-label>{{selectedEntity.resource.name} ...

Simultaneous appearance of multiple jQuery dialogs

As I work on creating a team page, each team member has their own div that contains a photo and employee information. My goal is to have a dialog box pop up when the photo is clicked, using the $this context to retrieve the employee data from the same div. ...

Waiting for multiple asynchronous calls in Node.js is a common challenge that many developers

I'm facing a dilemma trying to execute multiple MongoDB queries before rendering a Jade template. I am struggling to find a way to ensure that all the Mongo Queries are completed before proceeding with rendering the template. exports.init = funct ...

Typescript: Add a new variable preceding a specified string

fetchArticle(articleId: string): Observable<any> { return this._http.get(`${this._url}/${articleId}`) .map((response: Response) => response.json()) .do(value => console.log(value)) .catch((error) => Observable.throw(err ...

Encountering issues in d3.js following the transition to Angular 8

After upgrading my Angular 4 app to Angular 8, I encountered an issue where the application works fine in development build but breaks in production build. Upon loading the application, the following error is displayed. Uncaught TypeError: Cannot read p ...

Using NodeJS to retrieve a string from HTML code

Below is the provided HTML code snippet: <iframe width="100%" height="166" scrolling="no" frameborder="no" src="http://w.soundcloud.com/player/?url=http%3A%2F%2Fapi.soundcloud.com%2Ftracks%2F11111111&amp;auto_play=false &amp;show_artwork=true& ...

Having trouble getting my images to load in React. Seems like a common issue that many people run into

UPDATE: After trying different paths for my image import (such as 'import Github from '../..img/github.png'), the errors have disappeared but the image still won't load on my app. Folder Structure: My-Portfolio node_modules public src ...

Retrieve all `div` elements within the shadow root that have a matching class name

I have discovered a shadowRoot within my HTML page, which I am able to access using the following code snippet: var shadow = document.getElementById( "3rd-party-div" ).shadowRoot; Upon further examination, I noticed that there are ...

Encountering a jQuery error while attempting to initiate an AJAX request

I'm currently working on a project in SharePoint and I want to integrate JQuery to make an ajax call from the homepage. However, when I attempt to make the call, I encounter an error stating "Array.prototype.slice: 'this' is not a JavaScript ...

Error message in Angular 2: "__generator is not recognized"

I've been working on intercepting outgoing HTTP requests in Angular 2 in order to generate a token from the request body and attach it to the header of each post request. Below is the code snippet that I've implemented. Initially, I encountered ...

Exploring table iteration in Angular 7

I am looking to create a table with one property per cell, but I want each row to contain 4 cells before moving on to the next row... This is what I want: <table> <tr> <td> <mat-checkbox>1</mat-checkbox& ...