Svelte 5 Component Library - How to export types for property interfaces #13164
Replies: 3 comments
-
same problem here |
Beta Was this translation helpful? Give feedback.
-
Not sure whether this should work. Personally, I would probably not export props interfaces but resolve the type where it's needed via the generic helper types from E.g. <script lang="ts">
import Label from '$lib/Label.svelte';
import type { ComponentProps } from 'svelte';
let props: ComponentProps<typeof Label> = {
// ...
};
</script> |
Beta Was this translation helpful? Give feedback.
-
Related, generics cannot currently be used with a standalone props type declaration because of the export limitation. <script lang="ts" generics="T">
// works:
const {v}: {v: T} = $props();
// fails: Return type of exported function has or is using private name 'Props'.ts(4060)
interface Props {
v: T;
}
const {v}: Props = $props();
// fails: Modifiers cannot appear here. If this is a declare statement,
// move it into <script context="module">..</script>ts(1184)
export interface Props { And generics can't be referenced or declared in the module script. |
Beta Was this translation helpful? Give feedback.
-
I'm working on a reusable Svelte 5 component library. When I try to import and use the library, VSCode complains about the types of all the attributes:
Type 'string' is not assignable to type 'never'.ts(2322)
This is how I'm trying to use the component:
<Label for="name_input_id">Name</Label>
This is how I'm defining the prop interface in Label.svelte:
My build command is using sveltekit to build and package the library:
The resulting Label.svelte.d.ts file seems to remove my interface defintion:
I'm using the following lib versions:
Svelte - 5.0.0-next.244
@sveltejs/package - 2.3.4
@sveltejs/kit - 2.5.24
Specific questions:
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions