What is the type
of a lucide-svelte
icon?
#1585
-
Hi. Anyone mind telling me what the
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 13 replies
-
Sorry for your the late reply, just see this. Import it from the library import { type Icon } from 'lucide-svelte' |
Beta Was this translation helpful? Give feedback.
-
Hey! I was successful with this code with /**
* @type {import('svelte').ComponentType<import('lucide-svelte').Icon>?}
*/
export let icon = null; But then with v0.302.0 I got the following error :
How can I type a prop so it will allow passing an icon like this with type safety :
<script>
import { User } from 'lucide-svelte';
</script>
<Component icon={User} />
<script>
/**
* @type {import('svelte').ComponentType<import('lucide-svelte').Icon>?}
*/
export let icon = null;
</script>
<svelte:component this={icon} /> NB. This is just a simple example, but I have a more complex component which use this logic. It used to work before. I haven't tested all versions between 294 and 302. |
Beta Was this translation helpful? Give feedback.
@shyakadavis if I got that right you should be able to do this then (when the type will be exported again in a fix release?) :
Your issue was probably with how svelte handle component prop types, you have to wrap it in a ComponentType<>.
I'll just let @ericfennis confirm that the
Icon
type should still be exported.