我试图创建一个常量来放置所有操作,但当我实现它时,我得到了他的错误:

Argument of type 'OperatorFunction<Action, Action>' is not assignable to parameter of type 'OperatorFunction<Action, { pageSize: number; pageIndex: number; }>'. Type 'Action' is missing the following properties from type '{ pageSize: number; pageIndex: number; }': pageSize, pageIndex

之前(工作正常):

paginateStudents$ = createEffect(()=>this.actions$.pipe(
        ofType('[Student List] Paginate students'),
        mergeMap((action: {pageSize: number; pageIndex: number})=> this.studentService.getAll(action.pageSize,action.pageIndex)
        .pipe(
            map((students: StudentResponse) => ({type: ACTIONS.PAGINATE_STUDENTS_SUCCESS, payload:{
                studentList: students.data,
                pageSize: students.pageSize
            }})),
            catchError(()=> EMPTY)
        ))
    ));

之后(不起作用):

paginateStudents$ = createEffect(()=>this.actions$.pipe(
        ofType(ACTIONS.PAGINATE_STUDENTS),
        mergeMap((action: {pageSize: number; pageIndex: number})=> this.studentService.getAll(action.pageSize,action.pageIndex)
        .pipe(
            map((students: StudentResponse) => ({type: ACTIONS.PAGINATE_STUDENTS_SUCCESS, payload:{
                studentList: students.data,
                pageSize: students.pageSize
            }})),
            catchError(()=> EMPTY)
        ))
    ));

常量操作列表:

export const ACTIONS = {
    ...
    PAGINATE_STUDENTS: '[Student List] Paginate students',
    ...
}

学生.操作:

export const paginatedStudents = createAction(
    ACTIONS.PAGINATE_STUDENTS_SUCCESS,
    props<{
        payload: {
            studentList: readonly Student[];
            pageSize: number
        }
    }>()
);

推荐答案

使用操作而不是操作的类型:

paginateStudents$ = createEffect(()=>this.actions$.pipe(
        ofType(paginatedStudents ),
        mergeMap((action: {pageSize: number; pageIndex: number})=> this.studentService.getAll(action.pageSize,action.pageIndex)
        .pipe(
            map((students: StudentResponse) => ({type: ACTIONS.PAGINATE_STUDENTS_SUCCESS, payload:{
                studentList: students.data,
                pageSize: students.pageSize
            }})),
            catchError(()=> EMPTY)
        ))
    ));

Angular相关问答推荐

Angular - MSAL用户缺少角色

文件阅读器未正确给出某些CSV文件的结果

Angular 如何观察DOM元素属性的变化?

MAT-复选框更改事件未在onSubscriberCheck函数中返回选中的值

如何防止变量值重置?

Angular 17-getEnvironment InjectorProviders出现异常

用于 React 的 ngx-extended-pdf-viewer

如何将 Angular 中的导航路由到同一页面并重新加载

Angular 不使用NgRx的简单CRUD应用程序

Angular Http 拦截器 - 修改标头会导致 CORS

Angular 15:在范围内提供相同标记时附加到提供的值

Angular6:RxJS switchMap 运算符未按预期工作

在 Angular 14 中找不到命名空间google

RxJS 基于先前的数据响应执行请求(涉及循环对象数组)

当访问令牌在 MSAL for Angular 中过期时如何重定向用户?

如何在对话框angular material内对齐按钮?

在Angular2中获取服务的域名

Angular 4.3 HttpClient:拦截响应

Angular CLI 为已经存在的组件创建 .spec 文件

如何使用 Angular CLI 删除包?