S
SolidJS12mo ago
Mr Void

Store item = undefined, causes typescript error

items[item.id] = undefined
items[item.id] = undefined
throws:
Type 'undefined' is not assignable to type '{ ...<item props> }'.ts(2322)
Type 'undefined' is not assignable to type '{ ...<item props> }'.ts(2322)
How to deal with this? I wish to avoid having undefined as a type: items: { [key: string]: Item | undefined }
4 Replies
Brendonovich
Brendonovich12mo ago
Are you trying to remove that entry from the store? delete items[item.id] is how you'd do that
Mr Void
Mr VoidOP12mo ago
Alright will try doing that. In the docs it is mentioned that to remove a value from some object it should be set to undefined.
Brendonovich
Brendonovich12mo ago
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!.
REEEEE
REEEEE12mo ago
You have to use the store setter to use the undefined method of deletion afaik
Want results from more Discord servers?
Add your server