相关文章推荐
风流的松树  ·  Unity ...·  昨天    · 
帅气的领带  ·  当遇到非法 URL ...·  昨天    · 
闯红灯的煎鸡蛋  ·  HttpUtility.UrlEncode ...·  17 小时前    · 
刚分手的马铃薯  ·  WebUtility.UrlEncode(S ...·  17 小时前    · 
奋斗的馒头  ·  SQL NULL 值 – IS NULL ...·  10 月前    · 
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));
                Thank you, this is also correct for the first problem but unfortunately I can mark only one answer.
– Fresco
                Dec 21, 2017 at 9:40
                let logged: number = localStorage.getItem('logged'); returns Type 'string' is not assignable to type 'number'.
– Fresco
                Dec 21, 2017 at 9:29
        

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.