类型 'Observable<Observable<Object[]>>' 不可分配给类型 'Observable<Object[]>'

Type 'Observable<Observable<Object[]>>' is not assignable to type 'Observable<Object[]>'

这曾经在 Angular 2/4 中工作,但自从我升级到 Angular 7 后,我在整个应用程序中都遇到了这个错误。突然可能是什么问题?

Type 'Observable<Observable<Object[]>>' is not assignable to type 'Observable<Object[]>'


Type 'Observable<Object>' is not assignable to type 'Observable<object[]>'.
  Type 'Object' is not assignable to type 'object[]'.
    The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead?
      Property 'includes' is missing in type 'Object'.

我尝试使用 'any' 类型,但它仍然有同样的错误。

受影响的代码:

getProfiles(): Observable<any[]> {
    const _url: string = this._serviceUrl + 'api/GetUserProfiles/';
    return this._http.get(_url)
        .catch(this.handleError);
}

调用方法

 this._exceptionService.getProfiles().subscribe(data => {
    this.data = data[0];
    }

package.json

"@angular/animations": "^7.0.0",
"@angular/cdk": "^7.0.0",
"@angular/common": "^7.0.0",
"@angular/compiler": "^7.0.0",
"@angular/core": "^7.0.0",
"@angular/forms": "^7.0.0",
"@angular/http": "^7.0.0",
"@angular/material": "^7.0.0",
"@angular/platform-browser": "^7.0.0",
"@angular/platform-browser-dynamic": "^7.0.0",
"@angular/router": "^7.0.0",

我运行以前遇到过这个问题。将您的 Observable 更改为 return any

Remove the array brackets []

  getProfiles(): Observable<any> {
        const _url: string = this._serviceUrl + 'api/GetUserProfiles/';
        return this._http.get(_url)
            .catch(this.handleError);
    }