#Can't get the localstorage data back

5 messages · Page 1 of 1 (latest)

balmy sage
#

Hey, why I can't get the localStorage data? it says: 'Argument of type 'string | null' is not assignable to parameter of type 'string'. It is because the getItem is either could return a string or null and the Json.parse is expecting a string so there is a type misunderstanding. How can I solve that ??

cyan tide
#

Use type guards

dim geyser
#

Or type assertions

#

It is possible, if nothing exists in localstorage that getitem returns nothing, and that is not valid JSON that can be parsed so you have to make sure that's it at least text

sly stump
#

Use a type and cast your get item call as it.