Observable<{}> not assignable to type Observable

前端 未结 5 997
自闭症患者
自闭症患者 2020-12-08 10:04

I\'m learning Angular2 and Typescript. I\'m working through the Heroes tutorial on angular.io, but applying it to a project I\'m converting from ASP.Net. I\'ve run into a pr

5条回答
  •  南方客
    南方客 (楼主)
    2020-12-08 10:22

    I had same problem, however no matter how I changed as above mentioned,It still not working. Until my college found this map, catch defination as VSC prompted

    so the proper change should be like (add type cast the following place)

    getRisks(): Observable {
      return this.http.get(this.serviceUrl)
        .map(this.extractData)
        .catch(this.handleError);
    }
    

    I am new to TypeScript. so this kind of [method signature] really give me a hammer on the head :(

    But finally it worked out :)

提交回复
热议问题