Typing
To add TypeScript Types for props, we can add a TypeScript Props
interface to the component frontmatter.
---
interface Props {
name: string;
greeting?: string;
}
const { greeting = 'Hello', name } = Astro.props;
---
<h2>{greeting}, {name}!</h2>
If the component must be passed children to its default slot, we can enforce this by using type Props = { children: any; };
.