当前位置: 首页 > 知识库问答 >
问题:

前端 - ts提示 找不到名称“localStorage”。ts(2304) ?

龚苏燕
2023-08-29

vue3 + ts项目,使用localStorage获取本地存储,ts报错

image.png
这该咋整?

共有1个答案

居和顺
2023-08-29
declare global {  interface Window {    localStorage: Storage;  }}

tsconfig.json

{  "compilerOptions": {    "target": "esnext",    "module": "esnext",    "strict": true,    "jsx": "preserve",    "importHelpers": true,    "moduleResolution": "node",    "experimentalDecorators": true,    "skipLibCheck": true,    "esModuleInterop": true,    "allowSyntheticDefaultImports": true,    "sourceMap": true,    "baseUrl": ".",    "isolatedModules": false,    "noImplicitAny": false, // 默认不声明类型的时候为any    "types": [      "vite/client",      "node"    ],    "paths": {      "@/*": [        "src/*"      ]    },    "lib": [      "esnext",      "dom",      "dom.iterable",      "scripthost"    ]  },  "include": [    "src/**/*.ts",    "src/**/*.tsx",    "src/**/*.vue",    "tests/**/*.ts",    "tests/**/*.tsx"  ],  "exclude": [    "node_modules"  ]}
 类似资料: