Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/30.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 作用于ngrx效应的类型不匹配_Angular_Typescript_Visual Studio Code_Ngrx_Ngrx Effects - Fatal编程技术网

Angular 作用于ngrx效应的类型不匹配

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

我创建了一个包含以下3个操作的操作文件:

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),
    ...
);