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 回答6k 阅读✓ 已解决
9 回答9.4k 阅读
6 回答5k 阅读✓ 已解决
3 回答10.5k 阅读✓ 已解决
4 回答7.3k 阅读
5 回答7.3k 阅读✓ 已解决
5 回答8.3k 阅读
tsconfig.json
localStorage
是 DOM 的内容,需要声明包含 DOM 库