为什么我的副作用操作无法识别我的 return 操作类型 属性?

Why my side effect action can't recognize my return action type property?

我正在尝试为我的身份验证存储设置 SideEffect。每次我触发操作 (TrySignIn) 我都会收到以下错误:

"AuthEffects.authSignin" dispatched an invalid action

ERROR TypeError: Actions must have a type property

我的理解是,从错误类型来看,我的 return 操作没有类型 属性,这里不是这种情况,我正在 returning 两个操作, SIGNINSET_TOKEN 并且它们都有类型属性。

如果有人能告诉我我做错了什么,我将不胜感激,

编辑:

我重现了错误 here,您将能够在控制台中看到与我收到的相同的错误。

我正在发布我的实现的相关代码,

我的 AuthActions

export class TrySignin implements Action {
  readonly type = TRY_SIGNIN;

  constructor(public payload: Credentials) {}
}

export class Signin implements Action {
  readonly type = SIGNIN;
}

export class SetToken implements Action {
  readonly type = SET_TOKEN;

  constructor(public payload: string) {}
}

我的副作用,

@Injectable()
export class AuthEffects {
  @Effect()
  authSignin = this.actions$
    .ofType(AuthActions.TRY_SIGNIN)
    .map((action: AuthActions.TrySignin) => {
      return action.payload;
    }).switchMap(
      (authData: Credentials) => {
         return (this.httpService.postRequest('/Account/Login', (authData)));
      })
      .map(
        (res) => {
          console.log(res['authToken']);
          return [
            {
              type: AuthActions.SIGNIN
            },
            {
              type: AuthActions.SET_TOKEN,
              payload: res['authToken']
            }
          ];

        }
      );

在我的组件中,我触发了我的动作,

login() {
    this.store.dispatch(new authActions.TrySignin(this.loginForm.value));
}

效果会在派发的动作到达商店之前对其进行修改。看起来您正在修改正在进行的操作以将其转换(映射)为

      return [
        {
          type: AuthActions.SIGNIN
        },
        {
          type: AuthActions.SET_TOKEN,
          payload: res['authToken']
        }
      ];

^^ 这是一个数组。它不遵守 Action 接口(并且它没有类型 属性)。

如果你把它编辑成这样

      return {
          type: AuthActions.SIGNIN
        }

有用吗?

更新

从评论中提升:如果您希望您的操作分派其他操作,请使用 mergeMap()。它添加到现有的 observable,而不是替换它。