Angular NgRx效应:我做错了什么?

Angular NgRx效应:我做错了什么?,angular,ngrx,rxjs6,ngrx-effects,Angular,Ngrx,Rxjs6,Ngrx Effects,因此,我尝试根据在对/API/auth/login进行API调用时从服务器获得的用户类型来分派不同的操作数组 但我得到了一个错误: Argument of type '(res: { jwtToken: string; usertype: string; expiresIn: number; userId: string; }) => ({ type: Act...' is not assignable to parameter of type '(value: { jwtToken: s

因此,我尝试根据在对/API/auth/login进行API调用时从服务器获得的用户类型来分派不同的操作数组

但我得到了一个错误:

Argument of type '(res: { jwtToken: string; usertype: string; expiresIn: number; userId: string; }) => ({ type: Act...' is not assignable to parameter of type '(value: { jwtToken: string; usertype: string; expiresIn: number; userId: string; }, index: number...'.
  Type '({ type: ActionTypes; payload?: undefined; } | { type: ActionTypes; payload: string; } | { type: ...' is not assignable to type 'ObservableInput<{ type: ActionTypes; payload?: undefined; } | { type: ActionTypes; payload: strin...'.
    Type '({ type: ActionTypes; payload?: undefined; } | { type: ActionTypes; payload: string; } | { type: ...' is not assignable to type 'ObservableInput<{ type: ActionTypes; payload?: undefined; } | { type: ActionTypes; payload: strin...'.
      Type '({ type: ActionTypes; payload?: undefined; } | { type: ActionTypes; payload: string; } | { type: ...' is not assignable to type 'Iterable<{ type: ActionTypes; payload?: undefined; } | { type: ActionTypes; payload: string; } | ...'.
        Types of property '[Symbol.iterator]' are incompatible.
          Type '() => IterableIterator<{ type: ActionTypes; payload?: undefined; } | { type: ActionTypes; payload...' is not assignable to type '() => Iterator<{ type: ActionTypes; payload?: undefined; } | { type: ActionTypes; payload: string...'.
            Type 'IterableIterator<{ type: ActionTypes; payload?: undefined; } | { type: ActionTypes; payload: stri...' is not assignable to type 'Iterator<{ type: ActionTypes; payload?: undefined; } | { type: ActionTypes; payload: string; } | ...'.
              Types of property 'next' are incompatible.
                Type '{ (value?: any): IteratorResult<{ type: ActionTypes; payload?: undefined; } | { type: ActionTypes...' is not assignable to type '{ (value?: any): IteratorResult<{ type: ActionTypes; payload?: undefined; } | { type: ActionTypes...'. Two different types with this name exist, but they are unrelated.
                  Type 'IteratorResult<{ type: ActionTypes; payload?: undefined; } | { type: ActionTypes; payload: string...' is not assignable to type 'IteratorResult<{ type: ActionTypes; payload?: undefined; } | { type: ActionTypes; payload: string...'. Two different types with this name exist, but they are unrelated.
                    Type '{ type: ActionTypes; payload?: undefined; } | { type: ActionTypes; payload: string; } | { type: A...' is not assignable to type '{ type: ActionTypes; payload?: undefined; } | { type: ActionTypes; payload: string; } | { type: A...'. Two different types with this name exist, but they are unrelated.
                      Type '{ type: ActionTypes; payload: string; }' is not assignable to type '{ type: ActionTypes; payload?: undefined; } | { type: ActionTypes; payload: string; } | { type: A...'.
                        Type '{ type: ActionTypes; payload: string; }' is not assignable to type '{ type: ActionTypes; payload: string; }'. Two different types with this name exist, but they are unrelated.
                          Types of property 'type' are incompatible.
                            Type 'ActionTypes' is not assignable to type 'ActionTypes'. Two different types with this name exist, but they are unrelated.

如果我把管理员登录和用户登录分开,就可以了。但这意味着大部分代码都是相同的。有人能帮我吗?

我认为唯一的方法是打字作为动作:


根据错误:类型“ActionTypes”不可分配给类型“ActionTypes”。存在两个具有此名称的不同类型,但它们是不相关的。是否声明了多个ActionTypes enum/map?是的,一开始考虑过这一点。但后来我改变了我所有的动作,使其具有唯一的名称,我仍然会得到错误。但是@timdeschryver的回答对我来说很有用。谢谢你的快速回复。它的工作。这真的帮了我很大的忙!!太棒了,很高兴我能帮上忙!
Argument of type '(res: { jwtToken: string; usertype: string; expiresIn: number; userId: string; }) => ({ type: Act...' is not assignable to parameter of type '(value: { jwtToken: string; usertype: string; expiresIn: number; userId: string; }, index: number...'.
  Type '({ type: ActionTypes; payload?: undefined; } | { type: ActionTypes; payload: string; } | { type: ...' is not assignable to type 'ObservableInput<{ type: ActionTypes; payload?: undefined; } | { type: ActionTypes; payload: strin...'.
    Type '({ type: ActionTypes; payload?: undefined; } | { type: ActionTypes; payload: string; } | { type: ...' is not assignable to type 'ObservableInput<{ type: ActionTypes; payload?: undefined; } | { type: ActionTypes; payload: strin...'.
      Type '({ type: ActionTypes; payload?: undefined; } | { type: ActionTypes; payload: string; } | { type: ...' is not assignable to type 'Iterable<{ type: ActionTypes; payload?: undefined; } | { type: ActionTypes; payload: string; } | ...'.
        Types of property '[Symbol.iterator]' are incompatible.
          Type '() => IterableIterator<{ type: ActionTypes; payload?: undefined; } | { type: ActionTypes; payload...' is not assignable to type '() => Iterator<{ type: ActionTypes; payload?: undefined; } | { type: ActionTypes; payload: string...'.
            Type 'IterableIterator<{ type: ActionTypes; payload?: undefined; } | { type: ActionTypes; payload: stri...' is not assignable to type 'Iterator<{ type: ActionTypes; payload?: undefined; } | { type: ActionTypes; payload: string; } | ...'.
              Types of property 'next' are incompatible.
                Type '{ (value?: any): IteratorResult<{ type: ActionTypes; payload?: undefined; } | { type: ActionTypes...' is not assignable to type '{ (value?: any): IteratorResult<{ type: ActionTypes; payload?: undefined; } | { type: ActionTypes...'. Two different types with this name exist, but they are unrelated.
                  Type 'IteratorResult<{ type: ActionTypes; payload?: undefined; } | { type: ActionTypes; payload: string...' is not assignable to type 'IteratorResult<{ type: ActionTypes; payload?: undefined; } | { type: ActionTypes; payload: string...'. Two different types with this name exist, but they are unrelated.
                    Type '{ type: ActionTypes; payload?: undefined; } | { type: ActionTypes; payload: string; } | { type: A...' is not assignable to type '{ type: ActionTypes; payload?: undefined; } | { type: ActionTypes; payload: string; } | { type: A...'. Two different types with this name exist, but they are unrelated.
                      Type '{ type: ActionTypes; payload: string; }' is not assignable to type '{ type: ActionTypes; payload?: undefined; } | { type: ActionTypes; payload: string; } | { type: A...'.
                        Type '{ type: ActionTypes; payload: string; }' is not assignable to type '{ type: ActionTypes; payload: string; }'. Two different types with this name exist, but they are unrelated.
                          Types of property 'type' are incompatible.
                            Type 'ActionTypes' is not assignable to type 'ActionTypes'. Two different types with this name exist, but they are unrelated.
if (res.usertype === 'Admin') {
        this.router.navigate(['/admin-panel']);

        return [...actions, {type: AdminActions.ActionTypes.SetId, payload: res.userId} as Action];
} else {
        this.router.navigate(['/client-panel']);

        return [...actions, {type: UserActions.ActionTypes.SetId, payload: res.userId} as Action];
}