title: How do I get the type from an object variable in Typescript / Angular 7?
body: <p>I'm trying to get the type/class from an custom object instance. This will then be used as a type parameter passed to a generic function rather than just use the 'any' type.</p>
  
  <p>I've tried foo.prototype, Object.getPrototypeOf(foo), typeof foo, foo.constructor, foo.constructor.name etc but haven't yet found a way to return the objects's type/class itself. The example below gives an idea of what I want to achieve - it doesn't work here because constructor.name only returns the name of the type:</p>
  
  <pre><code>var vehicle 
  
  if (selected == 'car') { 
  vehicle = new Car() 
  } else { 
  vehicle = new Bike()  
  } 
  
  var vehicleType = vehicle.constructor.name
  
  buildVehicle&lt;vehicleType&gt;(vehicle) 
  
  buildVehicle&lt;T&gt;(vehicle:T) { 
      do stuff… 
  }
  </code></pre>
  
  <p>I'm pretty new to typescript and javascript so I'm not sure this is even possible, but hopefully there is a way to do this.</p>
  
  <p>Thanks for any help on this.</p>