Property 'json' does not exist on type '{}'

前端 未结 2 1782
清歌不尽
清歌不尽 2020-12-15 19:01

I have an abstract base class in Typescript that looks like this:

import {Http, Headers, Response} from \'angular2/http\'; 
export abstract class SomeService         


        
相关标签:
2条回答
  • 2020-12-15 19:22

    You can get rid of this error by type-assertion to Response:

    .map((res: Response) => res.json())
    

    http.post() will return a Observable<Response> on wich map will require an Object of type Response. I think that's a missing definition in the current TypeScript AngularJS .d.ts.

    0 讨论(0)
  • 2020-12-15 19:26

    To me this looks strange...

    .map(res => (<Response>res).json())
    

    I would do

    .map((res: Response) => res.json())
    
    0 讨论(0)
提交回复
热议问题