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?
I would check that you are passing the correct interface into your store
injection.
Does IFlexBenefitTemplateState
exist on ICommonAppState
?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With