如何使Svelte知道自定义* .d.ts文件?

时间:2020-08-20 11:25:31

标签: typescript svelte

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

// global.d.ts
declare module "*.txt" {
    const content: string;
    export default content;
}
// test.ts
import txt from "./test.txt";

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

// Test.svelte
<script type="typescript">
    import txt from "./test.txt";
</script>

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

0 个答案:

没有答案
相关问题