Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/426.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
Javascript 类型为'的参数;(操作:用户&;TypedAction<;";登录开始";)=>;无效';_Javascript_Angular_Typescript_Ngrx_Ngrx Effects - Fatal编程技术网

Javascript 类型为'的参数;(操作:用户&;TypedAction<;";登录开始";)=>;无效';

Javascript 类型为'的参数;(操作:用户&;TypedAction<;";登录开始";)=>;无效';,javascript,angular,typescript,ngrx,ngrx-effects,Javascript,Angular,Typescript,Ngrx,Ngrx Effects,我是打字新手,正在angular11学习状态管理。当我创建效果时,它会给我一个类型为“(action:User&TypedAction)=>void”的错误参数 我试过这样做 login$ = createEffect(() => { return this.actions$.pipe( ofType(loginstart), // Argument of type '(action: User & TypedAction<"

我是打字新手,正在angular11学习状态管理。当我创建效果时,它会给我一个类型为“(action:User&TypedAction)=>void”的错误参数

我试过这样做

  login$ = createEffect(() => {
    return this.actions$.pipe(
      ofType(loginstart),

      //   Argument of type '(action: User & TypedAction<"login start">) => void' is not assignable to parameter of type '(value: User & TypedAction<"login start">, index: number) => ObservableInput<any>'.
      //   Type 'void' is not assignable to type 'ObservableInput<any>'
      exhaustMap((action) => {
        console.log(action);
      })
    );
  });

Action
const LOGIN_START = 'login start';
export const loginstart = createAction(LOGIN_START, props<User>());

export interface User {
  name: string;
  email: string;
}
login$=createEffect(()=>{
返回此.actions$.pipe(
类型(loginstart),
//类型为“(action:User&TypedAction)=>void”的参数不可分配给类型为“(value:User&TypedAction,index:number)=>ObservableInput”的参数。
//类型“void”不可分配给类型“ObservableInput”
排气图((动作)=>{
控制台日志(操作);
})
);
});
行动
const LOGIN_START='LOGIN START';
export const loginstart=createAction(LOGIN_START,props());
导出接口用户{
名称:字符串;
电子邮件:字符串;
}

我该如何解决这个问题呢?

这基本上是因为你没有从效果中恢复行动

      @Effect()
  login$ = createEffect(() => {
    return this.actions$.pipe(
      ofType(loginstart),

      //   Argument of type '(action: User & TypedAction<"login start">) => void' is not assignable to parameter of type '(value: User & TypedAction<"login start">, index: number) => ObservableInput<any>'.
      //   Type 'void' is not assignable to type 'ObservableInput<any>'
      exhaustMap((action) => {
        console.log(action);
        return of(someAction)
      })
    );
  });
  constructor(private actions$: Actions) {}

您应该返回可观察的内部排气图
export const someAction = createAction('login start success or something');