我想将一些*.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
中的声明?