title: I want to convert a angular2 observable to a class
body: <p>I am new in angular2 and I broke spend a lot of time to find a solution, but I didn't. I want to convert a oberservable from a http call store in a class. </p>
  
  <p>I have the following:</p>
  
  <p>json file</p>
  
  <pre><code>[{
      "nickname": "magicMike",
      "id": "123",
      "name": "Michael",
      "nachname": "Fischer",
      "pictURL": "../images/mainPanel/Image_dummy.jpg",
      "city": "Ulm"
  }]
  </code></pre>
  
  <p>the user class file:</p>
  
  <pre><code>export class User {
  
    nickname: string;
    id: string;
    name: string;
    nachname: string;
    pictURL: string;
    city: string;
  
  
    constructor(
      nickname: string,
       id: string,
       name: string,
       nachname: string,
       pictURL: string,
       city: string
    ){
      this.nickname = nickname;
      this.id = id;
      this.name = name;
      this.nachname = nachname;
      this.pictURL = pictURL;
      this.city = city;
    }
  }
  </code></pre>
  
  <p>The service which read the a json file</p>
  
  <pre><code>import { Component, Input } from '@angular/core';
  import { Injectable }     from '@angular/core';
  import { Http, Response, Headers, RequestOptions } from '@angular/http';
  import {Observable} from 'rxjs/Rx';
  import 'rxjs/add/operator/map';
  import 'rxjs/add/operator/catch';
  import { User } from './user'
  
  @Injectable()
  export class UserService {
     user: Array&lt;User&gt;;
    private useUrl = '/json/user.json';
    constructor(private http: Http) {
  
    }
  
  
  
    getUser(): Observable&lt;any&gt; {
      return this.http.get(this.useUrl)
        .map(this.extractData)
        .do(data =&gt; console.log("User from json: " + JSON.stringify(data)))
        .catch(this.handleError);
    }
  
    private extractData(response: Response) {
      let body = response.json();
      return body || {};
    }
  
  
    private handleError(error: Response) {
      console.log(error);
      return Observable.throw(error.json().error || "500 internal server error");
    }
  </code></pre>
  
  <p>And the componenten which take the oberservable and store it to the a array</p>
  
  <pre><code>   .......
  export class AppComponent implements OnInit {
  
  
        public user: User[];
  
       ngOnInit() {
          this.userService.getUser()
            .map((user: Array&lt;any&gt;) =&gt; {
              let result:Array&lt;User&gt; = [];
              if (user) {
                user.forEach((erg) =&gt; {
                  result.push(new User(erg.nickname, erg.id, erg.name, erg.nachname, erg.pictURL, erg.city ));
                });
                }
  
              })
            .subscribe(user =&gt; this.user = user);
        }
  ....
  </code></pre>
  
  <p>As I run this I getting the following error. </p>
  
  <pre><code>C:/Users/Lenovo/Documents/ui-challenger.one/src/app/app.component.ts (53,26): Type 'void' is not assignable to type 'User[]'.)
  </code></pre>
  
  <p>I hope anyone out there can help me on that. I just want to parse of a json file into a class that i can read the properties like this "User.name"</p>