Skip to content

Astro.props is type as any when use Polymorphic #10347

@RodrigoTomeES

Description

@RodrigoTomeES

Astro Info

Astro                    v4.4.13
Node                     v20.9.0
System                   Windows (x64)
Package Manager          pnpm
Output                   hybrid
Adapter                  @astrojs/vercel/serverless
Integrations             @astrojs/tailwind

If this issue only occurs in one browser, which browser is a problem?

No response

Describe the Bug

Astro.props is type as any

image

---
import type { HTMLTag, Polymorphic } from "astro/types"

type Props<Tag extends HTMLTag> = Polymorphic<{
	as: Tag
	variant: keyof typeof variantClasses
	color: keyof typeof colorClasses
}>

const { as: Tag, class: className, variant, color, ...props } = Astro.props

const variantClasses = {
	h2: "text-lg font-medium uppercase lg:text-2xl",
	h3: "text-2xl font-semibold uppercase",
	body: "text-xl",
	medium: "text-md",
}

const colorClasses = {
	white: "text-white",
	black: "text-black",
	primary: "text-accent",
	neutral: "text-neutral-300",
}

const classes = [
	variantClasses[variant as keyof typeof variantClasses],
	colorClasses[color as keyof typeof colorClasses],
	className,
]
---

<Tag class:list={classes} {...props}>
	<slot />
</Tag>

What's the expected result?

That has the types of Props.

In the codesandbox the error not appear but try it in vscode and it will appear

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-yq21np?file=tsconfig.json,src%2Fpages%2Findex.astro

Participation

  • I am willing to submit a pull request for this issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions