title: Typescript - set default value for class members
body: <p>I have a simple model:</p>
  
  <pre><code>export class Profile extends ServerData {
    name: string;
    email: string;
    age: number;
  }
  </code></pre>
  
  <p>When I am make a call to the server (Angular 4, $http) I often get the following response:</p>
  
  <pre><code>{
    name: string;
    email: string;
  }
  </code></pre>
  
  <p>The <code>age</code> property is missing.</p>
  
  <p>Is there any way to use my model and create a default age in case it is missing?
  I would prefer not to have to create 2 separate models if possible.</p>
  
  <p>I don't want to create the age as an optional property - I need it, even if it is just with an incorrect default.</p>
  
  <p>UPDATE:</p>
  
  <p>This is the call I making to the server:</p>
  
  <p>results-manager.component.ts:</p>
  
  <pre><code>this.resultsManagerService.getResults(this.config.request.action, this.pagingAndSorting, this.args).subscribe(
    results =&gt; {
      this.results = this.results.concat(results as Profile[]);
  </code></pre>
  
  <p>results-manager.service.ts:</p>
  
  <pre><code>getResults(action: string, pagingAndSorting: PagingAndSorting, args: string[]): Observable&lt;Profile[]&gt; {
  return this.apiService.callServer(
    pagingAndSorting,
    action,
    ...args );
  </code></pre>
  
  <p>}</p>
  
  <p>The request works and I receive the response, but even if I define the default values (as suggested by @msanford's answer) they get removed when I receive the response back in the component. Likewise if i add a constructor to the model (as per Mike Tung's answer).</p>
  
  <p>It seems like the backend response is completely overwriting the model - not just assigning the values.</p>
  
  <p>How can I get it to just assign the values to the model and not remove the values it does not return?</p>