Error with Actions observable in @ngrx/effects using TypeScript 2.4.1

为君一笑 提交于 2019-11-30 04:13:58

问题


After updating to TypeScript 2.4.1, compiling projects that use the Actions observable from @ngrx/effects (version 2.0.3) sees the following error thrown:

Error TS2684: The 'this' context of type 'Actions' is not assignable to method's 'this' of type 'Observable<any>'.
Error TS7006: Parameter 'action' implicitly has an 'any' type.
Error TS2345: Argument of type 'Actions' is not assignable to parameter of type 'Observable<Action>'.
  Types of property 'lift' are incompatible.
    Type '(operator: Operator<any, Action>) => Observable<Action>' is not assignable to type '<R>(operator: Operator<Action, R>) => Observable<R>'.
      Types of parameters 'operator' and 'operator' are incompatible.
        Type 'Operator<Action, R>' is not assignable to type 'Operator<any, Action>'.
          Type 'R' is not assignable to type 'Action'.

How can this be resovled?


回答1:


TypeScript 2.4.1 more strictly enforces the the generic signature of the lift method in Observable and the Actions observable's implementation of lift fails the check.

The check can be disabled using the --noStrictGenericChecks command line flag or the noStrictGenericChecks compiler option (as a parameter in tsconfig.json's "compilerOptions" object).

An alternative to disabling the checks is to use TypeScript's interface augmentation to specify a correct signature:

import { Action } from "@ngrx/store";
import { Observable } from "rxjs/Observable";
import { Operator } from "rxjs/Operator";

declare module "@ngrx/effects/src/actions" {
    interface Actions {
        lift<R>(operator: Operator<Action, R>): Observable<R>;
    }
}

Note that the full path to the module/file must be used; it's not sufficient to specify @ngrx/effects as the module name.


This has been resolved with the release of @ngrx/effects 2.0.4.



来源:https://stackoverflow.com/questions/44938803/error-with-actions-observable-in-ngrx-effects-using-typescript-2-4-1

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!