使用 typescript 的 vscode 中的智能感知问题

问题描述 投票:0回答:1

我有一个通过 VSCode 编辑的打字稿项目。

我使用的是parcel,这意味着我必须将图像“导入”到代码中。默认情况下,打字稿不喜欢这样,所以我在我的存储库中添加了一个

declarations.d.ts
文件以允许这些。

由于某种原因,VSCode 仅在编辑器中打开声明文件时才考虑该文件。一旦我关闭文件,这些错误就会再次弹出:

找不到模块 [...] 或其相应的类型声明 ts(2307)

这是一个最小可重现示例,以及问题的屏幕录制

├── package.json
├── package-lock.json
└── src
    ├── assets
    │   └── image.png
    ├── declarations.d.ts
    ├── index.html
    └── main.ts

我尝试过的东西

  • 重新启动打字稿服务器
  • 退出并重新启动 vscode
  • 重启电脑
  • 重置 vscode 设置
  • 更新vscode
  • 干净地重新安装 vscode(包括扩展和设置)

设置

  • 操作系统:Debian
  • VScode:1.83.1 x64,使用 apt 从 .deb 安装
  • 扩展:无
typescript visual-studio-code parcel
1个回答
0
投票

只需将此配置文件添加到您的代码库中作为 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"]
}

© www.soinside.com 2019 - 2024. All rights reserved.