在javascript中缺少打字稿声明文件

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

我的项目是混合的javascript和打字稿文件。那是我的tsconfig.json文件:

"compilerOptions": {
  "target": "es2017",
  "baseUrl": ".",
  "checkJs": false,
  "allowJs": true, 
  "noImplicitAny": true,
  "strictNullChecks": true,
  "experimentalDecorators": true,
  "jsx": "react",
  "esModuleInterop": true,
  "isolatedModules": false,
  "noEmit": true,
  "moduleResolution": "node",
  "skipLibCheck": true,
}

我一直在我的javascript文件中(checkJs设置为false):

Could not find a declaration file for module 'file1'. 'file1.js' implicitly has an 'any' type.ts(7016)

这些错误在import语句下显示为3个点,并且不会在vscode问题面板中添加错误计数。

屏幕截图:enter image description here

javascript typescript visual-studio-code
1个回答
0
投票

如果要导入这些JS文件,请在导入行之前使用// @ts-ignore注释。 TS编译器将跳过下一行的错误检查。

//@ts-ignore
import * as something from 'file1';
© www.soinside.com 2019 - 2024. All rights reserved.