Why am I getting a TS error in the following code
Heading.astro
// Heading.astro
const sizes = {
h1: "h1",
h2: "h2",
h3: "h3",
h4: "h4",
h5: "h5",
h6: "h6",
} as const;
interface Props {
tag: "h1" | "h2" | "h3" | "h4" | "h5" | "h6";
size: keyof typeof sizes;
title: string;
}
const { tag, size, title, ...rest } = Astro.props as Props;
const CustomTag = tag as any;
<CustomTag class={sizes[size]} {...rest}>
{title}
</CustomTag>
ContentBlock.astro
import SingleLineDeco from "@/assets/patterns/pattern-divide.svg";
interface Props {
title: string;
text: string;
class?: string;
}
const { title, text, class: className } = Astro.props;
<div>
<SingleLineDeco />
<slot name="heading" />
<p>{text}</p>
</div>
FeatureCard.astro
interface Props extends CustomPictureProps {
title: string;
text: string;
headingTag: string;
headingSize: string;
class?: string;
}
const {
headingTag,
headingSize,
title,
text,
mobileURL,
tabletURL,
desktopURL,
class: className,
} = Astro.props;
<div class:list={["feature", className]}>
<CustomPicture
desktopURL={desktopURL}
tabletURL={tabletURL}
mobileURL={mobileURL}
alt=""
class="feature__picture"
/>
<ContentBlock title={title} text={text}>
<Heading slot="heading" title={title} tag={headingTag} size={headingSize} />
</ContentBlock>
</div>
Features.astro
<FeatureCard
desktopURL={LandscapeDesktopImg}
tabletURL={LandscapeTabletImg}
mobileURL={LandscapeMobileImg}
alt=""
headingTag="h3"
headingSize="h3"
title="Enjoyable place for all the family"
text="Our relaxed surroundings make dining with us a great experience for everyone. We can even arrange a tour of the farm before your meal."
/>
error: Type 'string' is not assignable to type '"h1" | "h2" | "h3" | "h4" | "h5" | "h6"'.