Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MemoizedSelector is not assignable to parameter of type 'string'

I am using Angular 6 and NgRX 6.

I have a reducer that looks something like this -

export interface IFlexBenefitTemplateState {
  original: IFlexBenefitTemplate;
  changes: IFlexBenefitTemplate;
  count: number;
  loading: boolean;
}

export const INITIAL_STATE: IFlexBenefitTemplateState = {
  original: null,
  changes: null,
  count: 0,
  loading: true,
};

export default (state = INITIAL_STATE, { type, payload }) => {
  switch (type) {

    case STAGE_TEMPLATE_CHANGE:
      const pendingChanges = Object.assign({}, state.changes.sections);
      const newSection = Object.assign({}, pendingChanges[payload.key], payload, {
        changeType: 'updated',
      });

      return {
        ...state,
        changes: {
          sections: Object.assign({}, pendingChanges, { [payload.key]: { ...newSection } }),
        },
        count: !pendingChanges[payload.key].hasOwnProperty('changeType') ? state.count + 1 : state.count,
      };

    default:
      return state;
  }
};

I have a selector this grabbing state.count for me, which looks like this -

export const changesCount = createSelector(getStore, (state: IFlexBenefitTemplateState) => state.count);

And I am attempting to surface this is my template as follows -

@Component({
  selector: 'app-page-header-component',
  templateUrl: './page-header.component.html',
})
export class PageHeaderComponent implements OnInit {
  public count$: Observable<number>;

  public language: string;

  constructor(private store: Store<ICommonAppState>) {}

  ngOnInit(): void {
    this.count$ = this.store.select(changesCount);
    this.language = 'English';
  }
}

this.count$ is however returning the error

[ts] Argument of type 'MemoizedSelector<IBenefitsState, number>' is not assignable to parameter of type 'string'.

I cannot for the life of me understand what this is happening?

like image 615
Harry Blue Avatar asked Jul 09 '18 11:07

Harry Blue


2 Answers

I would check that you are passing the correct interface into your store injection.

Does IFlexBenefitTemplateState exist on ICommonAppState?

like image 184
nodediggity Avatar answered Nov 15 '22 04:11

nodediggity


I had the same error. The problem wasn't having the wrong interface in my store. Instead I was using the wrong selector.

Thanks to @nodediggity for getting me looking in the right direction.

like image 41
daotoad Avatar answered Nov 15 '22 04:11

daotoad