Аргумент типа «game» не может быть назначен параметру типа «(state: any) => IGame» - PullRequest
0 голосов
/ 17 марта 2020

Мой IGame интерфейс и начальное состояние выглядит следующим образом:

export interface IGame {
  currentScore: number;
  highScore: number;
  keepPlaying: boolean;
  won: boolean;
  gameOver: boolean;
  winningValue: number;
  tiles: ITile[];
}

let initialState: IGame = {
  currentScore: 0,
  highScore: parseInt(localStorage.getItem("highScore")) || 0,
  keepPlaying: false,
  won: false,
  gameOver: false,
  winningValue: 2048,
  tiles: []
};

при использовании его следующим образом:

export class GameService {
  public currentScore: Observable<number>;
  public highScore: Observable<number>;
  public tiles: Observable<ITile[] >;
  public gameOver: Observable<boolean>;
  public won: Observable<boolean>;

  constructor(private gridService: GridService, private store: Store<any>) {
    const store$ = store.select<IGame>('game');
    this.tiles = store$.pipe(map(({ tiles }: IGame) => tiles));
    this.currentScore = store$.pipe(
      map(({ currentScore }: IGame) => currentScore)
    );
    this.highScore = store$.pipe(map(({ highScore }: IGame) => highScore));
    this.gameOver = store$.pipe(map(({ gameOver }: IGame) => gameOver));
    this.won = store$.pipe(map(({ won }: IGame) => won));
  }

он выдает следующие ошибки:

ОШИБКА в app / game / 2048 / services / game.service.ts: 20: 40 - ошибка TS2345: Аргумент типа "game" не может быть присвоен параметру типа '(state: any) => IGame' .

Не понимаю почему, но, как я видел здесь https://ngrx.io/api/store/select он говорит, что мы можем пройти pathOrMapFn: string | ((state: T, props?: Props) => any)

...