title: How to directly assign HTTP response to an Interface Model type in Angular
body: <p><strong>app.component.ts</strong></p>
  
  <pre><code>import { Component,OnInit } from '@angular/core';
  import { DataServiceService } from './data-service.service';
  import {IModel} from './imodel';
  @Component({
    selector: 'my-app',
    templateUrl: './app.component.html',
    styleUrls: [ './app.component.css' ]
  })
  export class AppComponent  {
    name = 'Angular 5';
    resultArray:IModel;
    constructor(private dataService:DataServiceService){}
    ngOnInit(){
      this.dataService.getDataFromURL().subscribe((resultData)=&gt;{
        debugger
        this.resultArray=resultData;
      })
    }
  }
  </code></pre>
  
  <p><strong>dataservice.service.ts</strong></p>
  
  <pre><code>import { Injectable } from '@angular/core';
  import { HttpClient } from '@angular/common/http';
  
  @Injectable()
  export class DataServiceService {
  
    apiURL='https://jsonplaceholder.typicode.com/posts';
    constructor(private http:HttpClient) { }
  
    getDataFromURL(){
      return this.http.get(this.apiURL)
    }
  
  
  }
  </code></pre>
  
  <p><strong>imodel.ts</strong></p>
  
  <pre><code>export interface IModel {
         userId: number;
          id: number;
          title: string;
          body: string;
  }
  </code></pre>
  
  <p>I have created a Model Interface and trying to fetch data from an API.
  I have successfully retrieved the data but i am not able to assign the response to  resultArray which is an IModel type, which shows are error "Type 'Object' is not assignable to type 'IModel'.
    The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead?
      Property 'userId' is missing in type 'Object'.</p>