在ngrx选择器上键入不匹配

时间:2019-05-31 12:46:24

标签: angular store ngrx

我具有以下功能

  selectDrone(droneId: string) {
    this.store$.select(UsedDronesStoreSelectors.getUsedDroneEntityById(), { id: droneId })
    .pipe(take(1))
    .subscribe((drone) => {
      this.store$.dispatch(new UsedDronesStoreActions.SetSelectedUsedDrone({id : drone.id}));
    });
  } 

调用以下选择器

export const selectUsedDroneState: MemoizedSelector<object, State> = createFeatureSelector<State>('usedDrones');

export const getSelectedDrone = (state: State): number => state.selectedDrone;


export const selectAll: (state: object) => Array<IUsedDrone> = featureAdapter.getSelectors(selectUsedDroneState).selectAll;


export const getUsedDroneEntityById: () => MemoizedSelectorWithProps<object, {id: number}, IUsedDrone> = () => {
  return createSelector(
    selectAllEntities,
    (entities: Dictionary<IUsedDrone>, props: { id: number }) => {
      return entities[props.id];
    },
  );
};

问题是,由于某种原因,我在函数中遇到类型错误

  

'MemoizedSelectorWithProps'类型的参数不能分配给'“ usedDrones”类型的参数|   “无人机” | “任务””。无法将类型“ MemoizedSelectorWithProps”分配给类型“任务”

该错误显示了我所有的3家商店,所以我认为我使用的方式有误,但是我不明白为什么会这样。

0 个答案:

没有答案