如何让 Svelte 识别自定义 *.d.ts 文件?

ziy*_*ang 6 typescript svelte

我想将一些*.txt文件作为字符串导入到 svelte 组件中。以下打字稿代码在 VS Code 中不会引发警告:

// global.d.ts
declare module "*.txt" {
    const content: string;
    export default content;
}
Run Code Online (Sandbox Code Playgroud)
// test.ts
import txt from "./test.txt";
Run Code Online (Sandbox Code Playgroud)

但是,如果我尝试将相同的文本文件导入 Svelte 组件(虽然global.d.ts仍然存在):

// Test.svelte
<script type="typescript">
    import txt from "./test.txt";
</script>
Run Code Online (Sandbox Code Playgroud)

,VS Code 会抱怨Cannot find module './test.txt' or its corresponding type declarations. ts(2307)。那么如何正确地告诉 Svelte 里面的声明global.d.ts呢?