How to make Svelte aware of custom *.d.ts files?

Viewed 1937

I want to import some *.txt file as a string into a svelte component. The following typescript code raises no warning in VS Code:

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

However, if I try to import the same text file into a Svelte component (while global.d.ts still exists):

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

, VS Code will complain Cannot find module './test.txt' or its corresponding type declarations. ts(2307). So how to properly tell Svelte about the declarations inside global.d.ts?

0 Answers
Related