I want to use Array.prototype.includes
method in my ts file like.
const id = this.selectedItem.id;
ids.includes(id);
Where ids
is an array of numbers.
I always get a compilation error:
Argument of type 'number' is not assignable to parameter of type 'number & string'
When explicitly transform id to be a number Number(id)
, then I also see Type number is not assignable to type string
.
And when I explicitly transform id to be a string id.toString()
then I can see Type string is not assignable to type number
.
It is overwhelmig. How includes
method can be used in TypeScript? How to use it in my example?
[Edit] Extended example:
interface State extends EntityState<IItem> {}
this.stateSubscription = this.store.select((state: State) => state.items).subscribe(
val => {
const selectedId = this.selectedItem ? this.selectedItem.id : null;
val.ids.includes(selectedId);
}));
val.ids.includes(selectedId as any)
also doesn't work.