I have a starting SvelteKit project. I am trying to reuse an interface in multiple places.
The file is placed in /src/lib/choice.ts.
export interface Choice {
id: number;
value: string;
}
However, when I try to reference this interface in a Svelte component like so:
<script lang="ts">
import {Choice} from "$lib/choice";
</script>
I get this error:
500
The requested module '/src/lib/choice.ts' does not provide an export named 'Choice'
SyntaxError: The requested module '/src/lib/choice.ts' does not provide an export named 'Choice'
My IDE, however, thinks this is perfectly valid, up to and including allowing click-navigation to the Choice declaration.
If, however, I change the declaration to this:
export class Choice {
id!: number;
value!: string;
}
Everything works and my IDE is happy.
What's going on here? I don't understand why the interface doesn't work but the class declaration does.