JH-*_*Ren 2 ngrx-effects angular8
我正在使用 Angular 8 和 NGRX 8。我有一个操作:
export const loadEnvironment = createAction(
LicencingActionTypes.LoadEnvironment,
props<{environment: Environment}>()
);
Run Code Online (Sandbox Code Playgroud)
以及相应的效果:
loadEnvironment = createEffect(() => this.actions$.pipe(
ofType(LicencingActionTypes.LoadEnvironment),
exhaustMap((action) =>
this.authService.
getToken(LicencingEffects.getAuthDetailsForEnvironment(action.environment))
.pipe(
switchMap((token) => [
AuthActions.onLogin({token: token}),
LicencingActions.onLoadEnvironment({environment: action.environment})
]),
catchError(error => of(AuthActions.onLoginError({error: error})))
)
)
));
Run Code Online (Sandbox Code Playgroud)
我一直在阅读 NGRX 8 的文档(https://ngrx.io/guide/effects#incorporating-state)。
他们的示例表明您可以只使用操作属性而不强制转换操作的类型:
...
exhaustMap(action =>
this.authService.login(action.credentials)
...
Run Code Online (Sandbox Code Playgroud)
Webpack 无法编译,并且出现以下错误:
ERROR in src/app/licencing/effects/licencing.effects.ts(20,69): error TS2339: Property 'environment' does not exist on type 'never'.
Run Code Online (Sandbox Code Playgroud)
我哪里错了?
操作必须在操作文件底部的类型联合中声明:
const all = union({
info,
appError
});
export type CoreActionsUnion = typeof all;
Run Code Online (Sandbox Code Playgroud)
然后在 Effects 类构造函数中注入该类型作为 Actions 的类型参数:
constructor(private actions$: Actions<CoreActionsUnion>) { }
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1796 次 |
| 最近记录: |