Store item = undefined, causes typescript error
throws:
How to deal with this? I wish to avoid having
undefined
as a type: items: { [key: string]: Item | undefined }
4 Replies
Are you trying to remove that entry from the store?
delete items[item.id]
is how you'd do thatAlright will try doing that.
In the docs it is mentioned that to remove a value from some object it should be set to
undefined
.Oh good point, in that case the docs also say
In TypeScript, you can delete a value by using a non-null assertion, like undefined!
.
You have to use the store setter to use the undefined method of deletion afaik