title: Best practices for initializing Typescript classes from objects (Object.assign)
body: <p>I want to define a TypeScript class that will receive it's properties via a plain object (like a database document).</p>
  <pre><code>class Car {
     color: string;
     
     constructor(props: ???) {
         Object.assign(this, props)
     }
   
  }
  </code></pre>
  <p>What is the best way to type <code>props</code>?</p>
  <p>I could create another interface, called <code>CarProps</code> and define them there, like:</p>
  <pre><code>class Car implements CarProps { 
      constructor(props: CarProps) {
          Object.assign(this, props)
      }
  }
  </code></pre>
  <p>I am struggling with what to name the interface however, since the <a href="https://github.com/Microsoft/TypeScript-Handbook/issues/121" rel="nofollow noreferrer">TypeScript Handbook forbids starting interface names with &quot;I&quot;</a> (e.g. ICar). Since I would end up with an interface and class that define &quot;Car&quot;, they both cant have the same name, so one of them has to be offset like &quot;CarProps&quot;, &quot;ICar&quot;, or &quot;CarClass&quot;.</p>
  <p>A problem with this approach is that the properties must be defined twice:</p>
  <pre><code>interface CarProps {
    color: string;
  }
  
  class Car implements CarProps {
    color: string; // duplication here
  }
  </code></pre>
  <p>Some solutions are offered here (interface merging and abstract classes): <a href="https://stackoverflow.com/questions/62120880/why-the-need-to-redefine-properties-when-implementing-an-interface-in-typescript">Why the need to redefine properties when implementing an interface in TypeScript?</a></p>
  <p>Would appreciate any suggestions on the best practice for this approach.</p>