Answers for "json.parse argument of type 'string | null' is not assignable to parameter of type 'string'. type 'null' is not assignable to type 'string'.ts(2345)"

12

Argument of type 'string | null' is not assignable to parameter of type 'string'. Type 'null' is not assignable to type 'string'

this.currentUser = JSON.parse(localStorage.getItem('currentUser') || '{}');
Posted by: Guest on December-18-2020
1

JSON.parse(localStorage.getItem('users') Argument of type 'string | null' is not assignable to parameter of type 'string'. Type 'null' is not assignable to type 'string'.

this.currentUser = JSON.parse(localStorage.getItem('currentUser')!);
Posted by: Guest on April-20-2021

Code answers related to "json.parse argument of type 'string | null' is not assignable to parameter of type 'string'. type 'null' is not assignable to type 'string'.ts(2345)"

Code answers related to "TypeScript"

Browse Popular Code Answers by Language