相关文章推荐
暴躁的石榴  ·  翻译 - Dolibarr ERP CRM ...·  5 月前    · 
不羁的饺子  ·  Debezium | Apache Flink·  5 月前    · 
风流的板栗  ·  香港閱讀城·  1 年前    · 
考研的台灯  ·  OH 3.3.0 Frontail not ...·  1 年前    · 
知识渊博的斑马  ·  Excel ...·  2 年前    · 
自信的胡萝卜  ·  Nosql-neo4j-Cypher 语句 ...·  2 年前    · 
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.