#Store item = undefined, causes typescript error

4 messages · Page 1 of 1 (latest)

static pine
#
items[item.id] = undefined

throws:

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 }

opaque stump
#

Are you trying to remove that entry from the store? delete items[item.id] is how you'd do that

static pine
opaque stump
#

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!.