vue3 + ts项目,使用localStorage获取本地存储,ts报错
这该咋整?
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"
]
}
8 回答4.8k 阅读✓ 已解决
6 回答3.5k 阅读✓ 已解决
6 回答2.4k 阅读
5 回答6.4k 阅读✓ 已解决
3 回答2.5k 阅读✓ 已解决
3 回答2.2k 阅读✓ 已解决
3 回答2.6k 阅读✓ 已解决
tsconfig.json
localStorage
是 DOM 的内容,需要声明包含 DOM 库