Reputation: 21
Error: src/app/MyComponents/todos/todos.component.ts:13:5 - error TS2322: Type 'string | null' is not assignable to type 'string'. is not assignable to type 'string'. Type 'null' is not assignable to type 'string'.
13 this.localItem = localStorage.getItem("todos");
Upvotes: 0
Views: 702
Reputation: 118
Make sure that while setting the local storage item we should have called the token in the response like,
localStorage.setItem("jwt", response.token);
You have passed the token as the second parameter.
Go to developer tools in Google chrom and check for the local storage whether the name in the local storage and the name you have passed here are the same.
Upvotes: 0
Reputation: 1780
localStorage.getItem can return null. You need to add null check.
const todos = localStorage.getItem("todos");
if (todos) {
this.localItem = todos;
}
Upvotes: 1