This is my code:
class A{
test: string
constructor(test: string){
this.test = test
}
}
const a = new A("hi")
console.log(a)
This is my output:
A { test: 'hi' }
When I want to upload this as a Javascript object, it get's rejected because it ain't a Javascript object. I can make one by doing this:
const someJSON = JSON.stringify(a)
const javascriptObject = JSON.parse(someJSON)
But I think there must be a better way, this feels like a hack. How to convert a typescript class instance to a plain javascript object?
Type object. What exactly are you trying to achieve?a instanceof Objectit returnstrue.typeof "hello"outputsstring, not object, and yet is a valid JavaScript objectI want to upload this as a Javascript object, it get's rejected<= What exactly do you mean by"upload as a javascript object"and what do you mean by"rejected"? What does rejected mean? Is there an error message? If so please post it.