Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/407.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 类型';可观察<;HttpEvent<;T>&燃气轮机';不可分配给类型';可观察<;T>';_Javascript_Angular_Typescript - Fatal编程技术网

Javascript 类型';可观察<;HttpEvent<;T>&燃气轮机';不可分配给类型';可观察<;T>';

Javascript 类型';可观察<;HttpEvent<;T>&燃气轮机';不可分配给类型';可观察<;T>';,javascript,angular,typescript,Javascript,Angular,Typescript,问题出在第14行 Type 'Observable<HttpEvent<T>>' is not assignable to type 'Observable<T>'. Type 'HttpEvent<T>' is not assignable to type 'T'. 'HttpEvent<T>' is assignable to the constraint of type 'T', but 'T' could be in

问题出在第14行

Type 'Observable<HttpEvent<T>>' is not assignable to type 'Observable<T>'.
  Type 'HttpEvent<T>' is not assignable to type 'T'.
    'HttpEvent<T>' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint '{}'.
      Type 'HttpSentEvent' is not assignable to type 'T'.
        'HttpSentEvent' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint '{}'.ts(2322)
有很多重载,一些重载返回
可观察的
,另一些重载返回
可观察的
。如果
getHttpParams
的返回值是
any
,它认为您将得到后者

因此,最基本的解决方案是更具体地说明该方法可以返回什么,例如:

protected getHttpParams(obj: object): {headers: HttpHeaders, params?: HttpParams} { ... }

我想如果返回
getHttpParams
的类型更清晰,例如
{headers:HttpHeaders,params?:any}
,它会更快乐。否则,它似乎认为你在改变
观察
。该死,这就解决了这个问题。怎么做?因为否则它不知道您是否要观察响应,所以它无法在
Observable
Observable
之间进行选择。是因为这个参数:observe?:“body”;?是的,
observe
参数用于设置您应该期望的返回类型。
protected getHttpParams(obj: object): {headers: HttpHeaders, params?: HttpParams} { ... }