title: validate types of incoming data with TypeScript and Angular2
body: <p>I would like to know the recommended way to validate the data received from the server via <code>AJAX</code> or in child component via <code>@input</code> decorator in Angular2+ apps. In the app I currently work with I use interfaces for this, but they do not validate incoming data, i.e. when some property is missing, no run time errors about invalid type are issued:</p>
  
  <pre><code>// types.ts
  export interface IAuthItem {
  name: string;
  type: number;
  description: string;
  rule_name: string | any;
  data?: any;
  created_at: number;
  updated_at: number;
  selected?: boolean;
  }
  
  export interface IAuthItemFormModel {
  AuthItem: IAuthItem;
  oldAuthItem: IAuthItem;
  permissions: IAuthItem[];
  assignments: IAuthItem[];
  }
  
  // component.ts
  
  //other imports
  import { IAuthItemFormModel,  IAuthItem  } from './types.ts';
  
  ....
  
  @Input() model: IAuthItemFormModel;
  
    ngOnInit() {
    this.getData();
  }
  
  getData() {
    this.http.post('/api/admin/auth-item/form-data', 
      this.model).subscribe((data: IAuthItemFormModel) =&gt; {
    this.model = Object.assign(this.model, data);
    console.log(this.model);
    });
  }
  </code></pre>