Ngc: Error: the return type of the public method from the exported class has or uses the name "Observable" from the external module, but cannot be named

the code

this.store.select(state => state.user).subscribe(u => user = u).unsubscribe();

https://gist.github.com/nottinhill/eac309590096cc6f1b910f40a1b2f0c3 https://gist.github.com/nottinhill/5dc4026007a0c3ea3a4e0c15c0adfe05

Error

[02:25:41]  ngc: Error: Error at /Users/tyrion/devel/saveup-front/.tmp/+purchase/shared/purchase-service/purchase.service.ts:22:12: Return type of public method from exported class has or is using name 'Observable' from external module "/Users/tyrion/devel/saveup-front/node_modules/rxjs/Observable" but cannot be named.

Problem

Where is the strong type type observed here? I can not get it to compile with what I have tried so far.

+4
source share
2 answers

Well, this is something weird, but I managed to fix it using a private method inside the service: where you place the method this.store.select(state => state.user), if you use import {Http} from "@angular/http";, make sure you do something next to this:

import {Injectable} from '@angular/core';
import {Http, Response} from "@angular/http";
import 'rxjs/add/operator/catch';
import 'rxjs/add/operator/map';
import {Observable} from "rxjs";


@Injectable()
export class MyService {
  static get parameters() {
    return [[Http]];
  }

  constructor(private http: Http) {

  }

  getList() {
    var url = 'http://<URL_HERE>';
    var response = this.http.get(url).map(this.extractData).catch(this.handleError);

    console.log(response);
    return response;
  }


  private extractData(res: Response) {
    let body = res.json();
    return body || { };
  }

  private handleError (error: any) {
    let errMsg = (error.message) ? error.message :
      error.status ? `${error.status} - ${error.statusText}` : 'Server error';
    console.error(errMsg); // log to console instead
    return Observable.throw(errMsg);
  }
}

extractData, , , .

+1

Observable:<any> , Observables, .

+1

Source: https://habr.com/ru/post/1657333/


All Articles