我使用ofType运算符有 2 个动作和这 2 个动作的效果,如下所示:
export const myActions = {
actionA: createAction(`actionA`, props<{ a: string }>()),
actionB: createAction(`actionB`, props<{ b: number }>())
}
myEffect$ = createEffect(() =>
this.actions$.pipe(
ofType(myActions.actionA, myActions.actionB),
mergeMap(action => {
// How to convert action object to correct type and access action.a or action.b props?
if (action.type == myActions.actionA) {
console.log(action.a); // compile error
} else if (action.type == myActions.actionB) {
console.log(action.b); // compile error
}
})
), {dispatch: false}
);
Run Code Online (Sandbox Code Playgroud)
如何检查和访问动作的道具(action.a 和 action.b)并从 IDE …