Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
Returning with error:
Argument of type 'number' is not assignable to parameter of type
'string'
It's giving the same error when i use
getItem
to read the
logged
data.
Any solution?
All items in local storage are
strings
. You're trying to pass a number in as the second argument to
setItem
when
setItem
's second paramter is type
string
, so naturally TypeScript warns you (because you've asked for type safety) that you can't do that.
If you want to store in local storage, explicitly turn it into a string:
let dt: number = Date.now();
localStorage.setItem('logged', String(dt+864000000));
–
–
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.