Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

194
Views
ERROR TypeError: Cannot read properties of null (reading 'setItem')
private currentStorage = null;

setItem(key: string, value: string) {
    this.currentStorage.setItem(key, value);
}

When I run my code (the above snippet is the only one that contains the setItem) I get the following error:

ERROR TypeError: Cannot read properties of null (reading 'setItem')
    at SessionService.setItem (session.service.ts:53:23)
    at authentication.service.ts:58:37
    at map.js:7:1
    at OperatorSubscriber._next (OperatorSubscriber.js:13:1)
    at OperatorSubscriber.next (Subscriber.js:31:1)
    at map.js:7:1
    at OperatorSubscriber._next (OperatorSubscriber.js:13:1)
    at OperatorSubscriber.next (Subscriber.js:31:1)
    at filter.js:6:50
    at OperatorSubscriber._next (OperatorSubscriber.js:13:1)

I've tried many ways to define the currentStorage but the error is the same or sometimes says "properties of undefined" instead of "properties of null".

Can anyone explain what is happening?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

this was all could provide based on question

setItem(key: string, value: string) {
        if(this.currentStorage){
        this.currentStorage.setItem(key, value);
        }
        else{
         ...
         //could do nothing here or create the storage
         this.currentStorage = ...
         this.currentStorage.setItem(key, value);
        }
    }

but if you are looking for actual change needed for session storage

    setItem(key: string, value: string) : void {
            sessionStorage.setItem(key, JSON.stringify(value));
        }
    
    /** get an item from session storage */
    getItem(string: key) : any | undefined{
 let value = sessionStorage.getItem(key);
if(value){
return JSON.parse(value);
}
return undefined;
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!