我正在使用 Angular 8 和 NGRX 8。我有一个操作:
export const loadEnvironment = createAction(
LicencingActionTypes.LoadEnvironment,
props<{environment: Environment}>()
);
以及相应的效果:
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})))
)
)
));
我一直在阅读 NGRX 8 ( https://ngrx.io/guide/effects#incorporating-state ) 的文档。
他们的示例表明您可以只使用操作属性而不强制转换操作类型:
...
exhaustMap(action =>
this.authService.login(action.credentials)
...
Webpack 无法编译,并且出现以下错误:
ERROR in src/app/licencing/effects/licencing.effects.ts(20,69): error TS2339: Property 'environment' does not exist on type 'never'.
Screenshot of code with errors highlighted
我哪里出错了?
最佳答案
Action 必须在 Action 文件底部的类型联合中声明:
const all = union({
info,
appError
});
export type CoreActionsUnion = typeof all;
然后在 Effects 类构造函数中注入(inject)该类型作为 Actions 的类型参数:
constructor(private actions$: Actions<CoreActionsUnion>) { }
关于ngrx-effects - Ngrx 效果中类型 'never' 上不存在属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56966011/