#astro starlight types in svelte
4 messages · Page 1 of 1 (latest)
Hi @inland flower. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
Astro's Starlight framework allows you to use TypeScript for type safety and autocompletion. However, when it comes to using Astro components inside Svelte components, there are some limitations.
According to the Astro documentation, any UI framework component becomes an “island” of that framework. These components must be written entirely as valid code for that framework, using only its own imports and packages. You cannot import .astro components in a UI framework component (e.g. .jsx or .svelte).
However, you can use the Astro <slot /> pattern to pass static content generated by Astro components as children to your framework components inside an .astro component. Here's an example:
---import MyReactComponent from '../components/MyReactComponent.jsx';
import MyAstroComponent from '../components/MyAstroComponent.astro';---
<MyReactComponent>
<MyAstroComponent slot="name" />
</MyReactComponent>
As for importing types, you can use the ComponentProps type from astro/types to reference the Props accepted by a component even if they are not exported by the component itself. Here's an example:
---import type { ComponentProps } from 'astro/types';
import { Icon } from '@astrojs/starlight/icon';
type IconProps = ComponentProps<typeof Icon>;---
Source (https://starlight.astro.build/components/using-components/#component-props)