我目前正在学习角2,以Deborah Kurata的Pluralsight类(Angular 2:Getting Started)为例。目前为止这很棒,但对于我的生活来说,我似乎无法发现我的.catch
的返回类型应该是什么。在她的课程中,以及我迄今为止发现的每个示例中,返回类型都留空。什么是Http.get()。catch的返回类型?
这是我有:
getProducts(): Observable<IProduct[]> {
return this._http.get("someurl")
.map {.....}
.catch(this.handleError);
}
handleError (response: Response) **/*what goes here?*/** {
// the code in the course says Observable.throw, but chrome is
// complaining that there is no such function. I have tracked
// down "static throw: typeof ErrorObservable.create;" in
// Observable.ts but I'm not sure what's going on here.
}
谢谢@马丁。不幸的是,源代码不能说明太多(对我而言)。但是我看到了“输出函数_catch(this:Observable ,selector:(err:any,caught:Observable )=> ObservableInput ):Observable {...}所以,”_catch“(不是” catch“)是一个函数,它需要”this“(在TS中是如何工作的)和一个选择器函数,选择器函数返回ObservableInput ,而_catch本身返回Observable 。赶上“返回?(我也试图返回”Observable“,但当然它抱怨丢失的泛型类型。) –
@ emery.noel你能显示给你类型错误的确切代码吗? – martin