我有一个通过 VSCode 编辑的打字稿项目。
我使用的是parcel,这意味着我必须将图像“导入”到代码中。默认情况下,打字稿不喜欢这样,所以我在我的存储库中添加了一个
declarations.d.ts
文件以允许这些。
由于某种原因,VSCode 仅在编辑器中打开声明文件时才考虑该文件。一旦我关闭文件,这些错误就会再次弹出:
找不到模块 [...] 或其相应的类型声明 ts(2307)
├── package.json
├── package-lock.json
└── src
├── assets
│ └── image.png
├── declarations.d.ts
├── index.html
└── main.ts
只需将此配置文件添加到您的代码库中作为 tsconfig.json
{
"compilerOptions": {
"module": "commonjs",
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"forceConsistentCasingInFileNames": true,
"target": "ES2020",
"noImplicitAny": false,
"noUnusedLocals": true,
"noUnusedParameters": true,
"moduleResolution": "node",
"sourceMap": true,
"outDir": "dist",
"allowJs": true,
"noEmit": false,
"removeComments": true,
"baseUrl": "src",
"lib": ["ES6"]
},
"compileOnSave": false,
"include": ["./src/**/*", "tests/*.ts"],
"exclude": ["node_modules", "dist", "tests"]
}