The following code gives the Object is possibly null
error in line +localStorage.getItem('PID')
:
newPropID() {
if (localStorage.getItem('PID')) {
localStorage.setItem('PID', String(+localStorage.getItem('PID') + 1));
return +localStorage.getItem('PID');
} else {
localStorage.setItem('PID', '101');
return 101;
}
}
I want to check if there's a record in local storage and store another record. How can I fix this?