title: Typescript class instance to javascript object
body: <p>This is my code:</p>
  
  <pre><code>class A{
      test: string
      constructor(test: string){
          this.test = test
      }
  }
  const a = new A("hi")
  console.log(a)
  </code></pre>
  
  <p>This is my output:</p>
  
  <blockquote>
    <p>A { test: 'hi' }</p>
  </blockquote>
  
  <p>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:</p>
  
  <pre><code>const someJSON = JSON.stringify(a)
  const javascriptObject = JSON.parse(someJSON)
  </code></pre>
  
  <p>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?</p>