首页 > 解决方案 > 误报 Typescript 找不到模块警告

问题描述

我正在使用以下代码导入图标:

import Icon from "!svg-react-loader?name=Icon!../images/svg/item-thumbnail.svg"

在 Visual Studio Code 1.25.1 中,我从 tslint 收到以下警告:

[ts] 找不到模块 '!svg-react-loader?name=Icon!../images/svg/item-thumbnail.svg'。

即使我应用 tslint 忽略语句,我仍然会收到此警告:

// tslint:disable-next-line:no-implicit-dependencies

导入工作正常(即 WebPack 构建包时没有错误),但我真的很想摆脱这个警告。任何想法如何做到这一点?

标签: javascripttypescriptwebpacktslintsvg-react-loader

解决方案


要获得 tslint,您可以这样做

import MyIcon from '!svg-react-loader?name=Icon!./down-arrow.svg'

将此用于您的 tslint.conf

{
  "rules": {
    "no-implicit-dependencies": [
      true,
      ["!svg-react-loader?name=Icon!."]
    ]
  }
}

这有点乱,但它有效..本质上,您需要将整个加载程序字符串列入白名单。


推荐阅读