简体   繁体   中英

Argument of type is not assignable to parameter of type 'OperatorFunction<unknown[]>'

I have recently updated to Angular 9 and keep receiving this error in my user.effects.ts file:

ERROR in src/app/modules/core/store/user/user.effects.ts:30:9 - error TS2345: Argument of type 'OperatorFunction<IUser, { payload: Partial<IUser>; } & TypedAction<"[Use
r] Data Received">>' is not assignable to parameter of type 'OperatorFunction<unknown[], { payload: Partial<IUser>; } & TypedAction<"[User] Data Received">>'.
  Type 'IUser' is missing the following properties from type 'unknown[]': length, pop, push, concat, and 26 more.

30         map(
           ~~~~
31           (data: IUser) => UserActions.dataReceived({ payload: UserService.parseData(data) })
   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
32         )

My code is as follows:

  @Effect()
  getData$ = this.actions$.pipe(
    ofType(UserActions.getData),
    switchMap(() => {
      return this.userService.getUserById(localStorage.getItem('uid')).pipe(
        map(
          (data: IUser) => UserActions.dataReceived({ payload: UserService.parseData(data) })
        )
      );
    })
  );

Your code should be

new UserActions.dataReceived({ payload: UserService.parseData(data) })

Let me know if you still have any issue

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM