Javascript 类型为'的参数;(操作:用户&;TypedAction<;";登录开始";)=>;无效';
我是打字新手,正在angular11学习状态管理。当我创建效果时,它会给我一个类型为“(action:User&TypedAction)=>void”的错误参数 我试过这样做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<"
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');