title: Migrate from HttpModule to HttpClientModule. Angular 5
body: <p>I am trying to migrate from angular HttpModule to angular HttpClientModule.</p>
  
  <p>My current code working with HttpModule is as follows:</p>
  
  <pre><code>constructor(private _http: Http) { }
  
   token: IToken;
   errorMesage: string;
  
   private _candidateLoginUrl = 'http://myapi/v1/auth/login';
  
   login(userName: string, password: string): Observable&lt;IToken&gt; {
  
    let body = JSON.stringify({ username: userName, password: password });
    let headers = new Headers();
    headers.append("Content-Type", 'application/json');
    let options = new RequestOptions({ headers: headers });
  
    return this._http.post(this._candidateLoginUrl, body, options)
      .map((response: Response) =&gt; {
  
        this.token = &lt;any&gt;response.json().data;
  
        if (this.token &amp;&amp; this.token.token) {            
          localStorage.setItem('currentUser', JSON.stringify(this.token));
        }
  
        return this.token;
      })
      .catch(this.handleError);
    } 
  
    private handleError(error: Response) {
      return Observable.throw('You are not authorized to get this resource');
    }
  </code></pre>
  
  <p>In order to keep the same logic I have done the following:</p>
  
  <pre><code>constructor(private _http: HttpClient) { }
  
  token: IToken;
  errorMesage: string;
  
  private _candidateLoginUrl = 'http://myapi/v1/auth/login';
  
  login(userName: string, password: string): Observable&lt;IToken&gt; {
  
    let body = JSON.stringify({ username: userName, password: password });  
    const headers = new HttpHeaders().set("Content-Type", 'application/json');
  
    this._http.post(this._candidateLoginUrl, body, { headers })    
  
    .map((response: Response) =&gt; {
  
              this.token = &lt;any&gt;response;
  
              if (this.token &amp;&amp; this.token.token) {               
                localStorage.setItem('currentUser', JSON.stringify(this.token));
              }
  
              return this.token;
            })
  
    .catch(this.handleError);
  }
  
  private handleError(error: Response) {
    return Observable.throw('You are not authorized to get this resource');
  }
  </code></pre>
  
  <p>However, I am getting an error from the login function: "a function whose declare type either 'void' not any must return value". What is the right way to migrate my code to HttpClientModule?</p>