【问题标题】:Argument of type is not assignable to parameter of type 'OperatorFunction<unknown[]>'类型参数不可分配给“OperatorFunction<unknown[]>”类型的参数
【发布时间】:2020-07-24 14:40:29
【问题描述】:

我最近更新到 Angular 9 并在我的 user.effects.ts 文件中不断收到此错误:

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         )

我的代码如下:

  @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) })
        )
      );
    })
  );

【问题讨论】:

    标签: angular typescript redux rxjs ngrx


    【解决方案1】:

    你的代码应该是

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

    如果您还有任何问题,请告诉我

    【讨论】:

      猜你喜欢
      • 2021-11-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-28
      • 2018-12-30
      • 2020-06-23
      相关资源
      最近更新 更多