Terrance Jackson
Terrance Jackson

Reputation: 1069

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

This used to work in Angular 2/4 but since I upgraded to Angular 7, I am getting this error throughout my application. What could be the issue suddenly?

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'.

I tried using 'any' type but it still has the same error.

the affected code:

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

caller method

 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",

Upvotes: 0

Views: 2421

Answers (1)

CodeMan03
CodeMan03

Reputation: 226

I ran into this problem before. Change your Observable to return any

Remove the array brackets []

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

Upvotes: 4

Related Questions