Ngrx 效果中的 'never' 类型不存在 属性
Property does not exist on type 'never' in Ngrx effect
我正在使用 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
我哪里错了?
尝试如下更改您的 effect
-
loadEnvironment = createEffect(() => this.actions$.pipe(
ofType(loadEnvironment), //<-- this is your action
exhaustMap(action => //<-- getting rid of extra parenthesis
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})))
)
)
));
示例参考 implementation
必须在动作文件底部的类型联合中声明动作:
const all = union({
info,
appError
});
export type CoreActionsUnion = typeof all;
然后在 Effects class 构造函数中注入该类型作为 Actions 的类型参数:
constructor(private actions$: Actions<CoreActionsUnion>) { }
我正在使用 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
我哪里错了?
尝试如下更改您的 effect
-
loadEnvironment = createEffect(() => this.actions$.pipe(
ofType(loadEnvironment), //<-- this is your action
exhaustMap(action => //<-- getting rid of extra parenthesis
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})))
)
)
));
示例参考 implementation
必须在动作文件底部的类型联合中声明动作:
const all = union({
info,
appError
});
export type CoreActionsUnion = typeof all;
然后在 Effects class 构造函数中注入该类型作为 Actions 的类型参数:
constructor(private actions$: Actions<CoreActionsUnion>) { }