使用后缀 (?raw, ?url 等时的打字稿错误

Typescript errors when using a suffix (?raw, ?url etc

当我尝试导入带有后缀 (?component) 的 SVG 时,我的 vite 项目出现打字稿错误。如何配置打字稿以忽略这些后缀?

TS2307: Cannot find module './desktop-mark.svg?component' or its corresponding type declarations.

import DesktopLogoMark from './desktop-mark.svg?component';

您需要添加模块声明: https://www.typescriptlang.org/docs/handbook/modules.html#wildcard-module-declarations