如何删除 vscode 中的红色下划线错误? (打字稿)

how to remove red underline error in vscode? (typescript)

我正在使用 React-Native 开发一个应用程序,我正在使用 vscode 作为代码编辑器。 当我导入一些图像或包时,出现这些红色和黄色下划线错误。 如何解决这个问题?

One thing that I can't understand is only "Fontawesome" has no such error, but both "MaterialCommunityIcons" and "Ionicons" have red underline error. (Line 4,5,6)

当我将鼠标悬停在第 1 行黄色下划线时,它显示我正在跟随。

ESLint is disabled since its execution has not been approved or denied yet. Use the light bulb menu to open the approval dialog.

当我将鼠标悬停在第 5,6 行红色下划线时,它显示我正在跟随。

Could not find a declaration file for module 'react-native-vector-icons/MaterialCommunityIcons'.

我多次卸载并安装“react-native-vector-icons”包,但出现相同的错误。(完全不是错误,我认为只是输入错误。代码运行良好。) 我安装了以下扩展。

post 这些单独的问题很合适,但是:

  1. 第一行错误(禁用 ESLint):

这可能有几个原因,但鉴于错误消息,请在命令面板中尝试以下方法并允许 ESLint 访问:

cmd + shift + p,搜索 'ESLint: Manage Library Execution'

否则你可以检查其他解决方案,例如。这里:

  1. MaterialCommunityIcons类型声明缺失错误:

可能你还没有安装相应的类型 - 通过运行安装:

yarn install @types/react-native-vector-icons -D

  1. 无法从 *.png 导入错误:

默认情况下,typescript 不理解 *.png 个文件。您可以通过添加 *.d.ts(例如 assets.d.ts)文件(例如在顶级 types 文件夹中)来解决此问题,其中包含以下内容:

declare module '*.png' {
  const value: any;
  export = value;
}

确保文件位于 typescript 可以找到的路径(必须在 tsconfig.json 中的 compilerOptions.include 属性 中列出)。