Main Code:
export class TodosComponent implements OnInit{
todos!: Todo[];
localItem: string;
constructor(){
const data = localStorage.getItem("todos");
this.localItem = data;
if(this.localItem == null){
this.todos = [];
}
else{
console.log(this.todos);
this.todos = JSON.parse(data);
}
}
Here is the result of my compilation: ERROR src/app/MyComponents/todos/todos.component.ts:14:5 - error TS2322: Type 'string | null' is not assignable to type 'string'. Type 'null' is not assignable to type 'string'.
14 this.localItem = `custom text` item;
I attempted to resolve it by adding, const localItem: string | null = getValueFromSomewhere(); but unfortunately, it did not work as expected