0
I have the code below that is returning an error where I am not understanding how to solve. The log console of "Ret.value" returns {"id":1,"name":"Max"} string correctly, but in JSON.parse.
Argument of type 'string | null' is not assignable to parameter of type 'string'.
Type 'null' is not assignable to type 'string'.
/
async getObject() {
const ret = await Storage.get({ key: 'user' });
console.log(JSON.parse(ret.value)); // ERRO AQUI
console.log(JSON.parse('{"id":1,"name":"Max"}')); // SEM ERRO TUDO RETORNA NORMAL
}
I’m using Ionic with Reactjs, in Typescript.
I think it should be something simple, but I tried several examples and looked here, but nothing solved the problem.
Thank you very much :) It worked perfectly.
– Leonardo Peixe