Here is the code snippet I am working with:
class A{
test: string
constructor(test: string){
this.test = test
}
}
const a = new A("hi")
console.log(a)
This is what the output looks like:
A { test: 'hi' }
However, when attempting to upload this as a JavaScript object, it gets rejected since it's not recognized as one. One way to work around this is by using JSON.stringify and JSON.parse methods as shown below:
const someJSON = JSON.stringify(a)
const javascriptObject = JSON.parse(someJSON)
Although this method works, I believe there might be a more efficient solution that does not feel like a workaround. Is there a better way to convert a TypeScript class instance into a plain JavaScript object?