Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 649
cartant Avatar asked Jul 06 '17 02:07

cartant


Video Answer


1 Answers

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.

like image 137
cartant Avatar answered Oct 12 '22 03:10

cartant