我最近已更新到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) })
)
);
})
);
答案 0 :(得分:1)
您的代码应为
new UserActions.dataReceived({ payload: UserService.parseData(data) })
让我知道您是否还有任何问题