属性 'pipe' does not exist on type 'OperatorFunction<unknown, Team[]> 创建 Ngrx 效果时出错

Property 'pipe' does not exist on type 'OperatorFunction<unknown, Team[]> error while creating Ngrx effects

我正在使用@ngrx/effects 库创建效果服务。但我收到错误。错误似乎来自 switchMap 中的 action 参数。如果我将它悬停在 action:unknown 上,我认为 actionofType 运算符的结果。它不能从前一个运算符推断出类型吗?

//auth.effects.ts

import { Injectable } from '@angular/core';
import { Actions, createEffect, ofType } from '@ngrx/effects';
import * as AuthActions from './auth.actions';
import { map, Observable, switchMap } from 'rxjs';
import { ApiService } from 'src/app/services/api.service';
import { Team } from '../models/team.class';

@Injectable()
export class AuthEffects {
  constructor(private actions$: Actions, private apiService: ApiService) {}

  loadTeams$ = createEffect(() => {
    return this.actions$.pipe(
      ofType(AuthActions.loadTeams),
      switchMap((action) => this.apiService.getTeams()).pipe( // Property 'pipe' does not exist on type 'OperatorFunction<unknown, Team[]>
        map((teams: Team[]) => AuthActions.loadTeamsSuccess({ teams }))
      )
    );
  });
}

下面是我的操作。

//auth.actions.ts

import { createAction, props } from '@ngrx/store';
import { Team } from '../models/team.class';

export const loadTeams = createAction('[Auth] Load Teams from Server');

export const loadTeamsSuccess = createAction('[Auth] Load Teams Success', props<{ teams: Team[] }>());

export const loadFailure = createAction('[Auth] Load Failure');

由于语法错误,您似乎遇到了错误:

...
  switchMap((action) => this.apiService.getTeams().pipe(
    map((teams: Team[]) => AuthActions.loadTeamsSuccess({ teams }))
  ))
);
...