I have a problem with argument in dispatch => Error: "Argument of type 'string' is not assignable to parameter of type '{ id: string; }'."
export class CharacterDetailsComponent implements OnInit {
id: string | null= '';
characterDetail$!: Observable<DataFromAPI>;
constructor(
private router: ActivatedRoute,
private store$: Store
) {}
ngOnInit(): void {
this.id = this.router.snapshot.paramMap.get('id');
this.getCharacterDetail();
}
getCharacterDetail() {
if (!this.id) {
return;
}
this.store$.dispatch(getCharDetailData(this.id));
this.characterDetail$ = this.store$.select(charDetailsSelector);
}
}
So who know how to fix this?
CodePudding user response:
Do it like this:
this.store$.dispatch(getCharDetailData({id: this.id}));
CodePudding user response:
Can You change your id: string | null= '' to id: any | null= ''; or You can set your dataType string where you want to dispatch.