我有以下內容簡單的服務:鍵入'Observable <Response |觀察到<Response>>」是不能分配給輸入‘觀察的<Response>’
import { Injectable } from '@angular/core';
import { Http, Response } from '@angular/http';
import 'rxjs/add/observable/throw';
import 'rxjs/add/operator/catch';
import 'rxjs/add/operator/map';
import { Observable } from 'rxjs/Observable';
@Injectable()
export class AddressService {
constructor(private http: Http) { }
getAnything =(): Observable<Response> => {
return this.http.get('https://my_api.com')
.map(this.handleSuccess)
.catch(this.handleError);
}
handleError = (error: Response): Observable<Response> => {
return Observable.throw(error || 'Server Error');
}
handleSuccess = (response: Response): Observable<Response> => {
let body;
if (response.text()) {
body = response.json();
}
return body || {};
}
}
它是完美的工作,直到我從2.3.4升級到打字稿2.4。 1。現在
,升級後,我發現了奇怪的錯誤:
Type 'Observable<Response | Observable<Response>>' is not assignable to type 'Observable<Response>'
有什麼意義嗎? TS 2.4.x中的哪些更改會使我的應用程序停止正常工作?
你爲什麼要升級到2.4.x https://stackoverflow.com/questions/44793859/rxjs-subject-d-ts-error-class-subjectt-incorrectly-extends-base -class-obs/44793989#44793989 – CharanRoot
@Jonnysai我不確定我是否理解......你是說我無法升級到2.4.1? –
handleSuccess =(response:Response):Observable不返回可觀察對象,只是任何。事實上,你的返回類型是錯誤的,現在編譯器抱怨是一個好兆頭 –