javascript - 为什么 localStorage.getItem 总是返回字符串?

标签 javascript typescript

这很奇怪。我在 lib.dom.d.ts 中发现 localstorage.getItem 的类型返回 'string | null',但是当我在我的应用程序中使用它时,它总是返回字符串 为什么?

最佳答案

因为事情就是这样:

The keys and the values are always strings

请参阅文档:https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage

关于javascript - 为什么 localStorage.getItem 总是返回字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57848289/

相关文章:

typescript - TypeScript 是否能够根据另一个论点塑造一个论点?

javascript - 触发点击功能不正常

javascript - 将 ASP.NET Webforms OnClick 事件限制为一次

javascript - 如何在谷歌脚本中获取非空白单元格的范围

javascript - TypeScript 映射类型推断未按预期工作

javascript - 从 json 数据应用 ionic 选择过滤器选择

javascript - 引用 ts-check JS 文件的定义

javascript - 从 v8 shell 使用 stringify

javascript - 使用 jQuery 在 2 个 div 之间移动元素

node.js - Nodejs typescript : Property 'email' does not exist on type 'string | object'