Angular 作用于ngrx效应的类型不匹配
我创建了一个包含以下3个操作的操作文件:Angular 作用于ngrx效应的类型不匹配,angular,typescript,visual-studio-code,ngrx,ngrx-effects,Angular,Typescript,Visual Studio Code,Ngrx,Ngrx Effects,我创建了一个包含以下3个操作的操作文件: export const showLoading = createAction(`[application] Show warning notification`); export const hideLoading = createAction(`[application] Show error notification`); export const showHttpResponseError = createAction(`[application
export const showLoading = createAction(`[application] Show warning notification`);
export const hideLoading = createAction(`[application] Show error notification`);
export const showHttpResponseError = createAction(`[application] Show success notification`, props<{ error: HttpErrorResponse, nextAction: Action }>());
export type Actions = ReturnType<
typeof showLoading |
typeof hideLoading |
typeof showHttpResponseError
>;
但由于某些原因,VS Code intellisense无法识别开关映射中的动作类型,它表示动作类型为从不
:
我错过什么了吗?或者我如何强制执行它的类型,因为该操作是使用ngrx action creators创建的,我没有明确的类型。为了将来参考,如果有人遇到同样的问题,解决方法是键入注入的actions$
变量:
private actions$:actions
然后,intellisense可以工作,您不需要在开关映射中强制执行类型。为了完整性,有多种方法:
1) 类型
运算符的类型
ofType<AddAction>(CounterActions.AddAction)
我通常使用这样的类型:of type(MyActions.MY_ACTION)
。你试过了吗?是的,这是旧方法,当你自己定义action类时,这是有效的。但我正在切换到新的动作创建者,那个么你们实际上并没有什么类型的动作来执行它。。。
ofType<AddAction>(CounterActions.AddAction)
constructor(private actions$: Actions<CounterActions.Actions>
foo$ = createEffect(() => this.actions$.pipe(
ofType(addAction),
...
);