NgRX effects - Type 'Observable' is not assignable to type 'Observable'

前端 未结 9 1111
你的背包
你的背包 2020-12-16 10:12

While working with NgRX 8 my colleagues and me are frequently facing a weird error message when implementing the effects.

Type \'Observable

9条回答
  •  猫巷女王i
    2020-12-16 10:34

    I have seen similar error as well.

    Type 'Observable' is not assignable to type 'Observable | ((...args: any[]) => Observable)'
    

    The quickest way I identify what may have happened is after | separator. The type is usually Observable<{something}> or Observable<{something | another}>. There is a | separator and the second item is not an Observable. This is maybe the problem.

    If for example the observable expects to have Observable, but there is some pipe operator returns something other than Observable. The unexpected type will appended to the expected type in the error message, because for Observable, T does not exist in ((...args: any[]) => Observable)

    my interpretation of the message is

    Internal type of an object is unknown, because we do not know which type to expect Observable = Action or ((...args: any[]) => Observable) = unknown

    if the problem is not immediately obvious, I just comment out the each pipe operator one by one and see if error goes way. If it does, now I know this operator is the problem, than I focus on operator and find the problem.

    I am interested to read other users replys. Those two way always points me in the right direction.

提交回复
热议问题