title: Casting "bigger" objects into "smaller" objects in Typescript
body: <p>I'm having troubles with assigning bigger objects into smaller objects. But I think I can best describe it with a simple example:</p>
  
  <p>Suppose I have declared the Typescript interface:</p>
  
  <pre><code>export interface CrewMember {
     name: string;
     organizing_function?: string;
   }
  </code></pre>
  
  <p>I now retrieve from a database an array of objects like this:</p>
  
  <pre><code>[{
   id: "someID",
   name: "Jack"
  },{
   id: "someOtherID",
   name: "Jipp",
   organizing_function: "Being good at stuff"
  }]
  </code></pre>
  
  <p>I want to create an Array&lt; CrewMember > wherein to put the objects from the database. However, my problem is that the the objects from the database have an "ID" which "CrewMember" doesn't. Hence I cannot simply assign them because Typescript complains that the types are incompatible. </p>
  
  <p>I first tried something like this:</p>
  
  <pre><code>let crewmember : CrewMember = {
   name: database[0].name,
   organizing_function: database[0].organizing_function
  };
  </code></pre>
  
  <p>However this is (1) quite the amount of work as I have many different types that are much, much bigger than this and (2) difficult because organizing_function is an optional parameter. So, as I understand, I would have to write a ton of "IF" clauses to find out what properties are given or not on the database object and then assign correctly.</p>
  
  <p><strong>So what is the best way to approach "casting" an object with superfluous properties into another object with a lot of optional properties in Typescript?</strong></p>
  
  <p>Would really appreciate any help on this. Thank you in advance.</p>