Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Type 'Observable<void>' is not assignable to type 'Observable<JSON>'

  getStepList(): Observable<JSON>  {                  
            this.headers = new Headers();
            this.headers.append('Content-Type', 'application/json; charset=utf-8');                
            let options = new RequestOptions({
                method: RequestMethod.Post,
                url: "FeedbackMaster.aspx/getStepList",                   
                headers: this.headers,
                  body:{log:this.login}
            });
            return this._http.request(new Request(options)).retry(2)
            .map((response: Response)=>this.extractData(response))
            .do(data => {this.temp=data, console.log('getStepList:'+ JSON.stringify(JSON.parse(this.temp.d)))})
            .catch(this.handleError);                  
    }

    extractData(res: Response) {
           let body = res.json();
           return body || { }; //<--- not wrapped with data
     }
          handleError(error: any) {
         console.error('An error occurred', error);
          return Promise.reject(error.message || error);
   }  

.......................................................................................................

Error

[ts]
 Type 'Observable<void>' is not assignable to type 'Observable<JSON>'.
 Type 'void' is not assignable to type 'JSON'.

What is wrong in my code?

like image 623
User Avatar asked Feb 17 '17 05:02

User


People also ask

Is it possible to type observable<void> as a JSON type?

[ts] Type 'Observable<void>' is not assignable to type 'Observable<JSON>'. Type 'void' is not assignable to type 'JSON'. What is wrong in my code?

Is 'observable<any> type assignable to 'products[]'?

Type 'Observable<any>' is not assignable to type 'Products []'. Property 'length' is missing in type 'Observable<any>'

Is it possible to type'observable<JSON>'in a void type?

....................................................................................................... [ts] Type 'Observable<void>' is not assignable to type 'Observable<JSON>'. Type 'void' is not assignable to type 'JSON'. What is wrong in my code? Show activity on this post.

Which type is not assignable to type'observable<JSON>'?

Bookmark this question. Show activity on this post. ....................................................................................................... [ts] Type 'Observable<void>' is not assignable to type 'Observable<JSON>'. Type 'void' is not assignable to type 'JSON'.


1 Answers

.map()needs to return something, for example:

.map((response: Response) => { this.extractData(response); return response.json(); })

The return response.json() yields Observable<JSON>. Without returning anything from .map() it becomes Observable<void>.

like image 99
Markus Pscheidt Avatar answered Sep 23 '22 09:09

Markus Pscheidt