-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Astro.props is type as any when use Polymorphic #10347
Comments
I suspect that this is a compiler issue, most likely related to withastro/compiler#927 in some ways |
Maybe we need to document that -type Props<Tag extends HTMLTag> = Polymorphic<{
+type Props<Tag extends HTMLTag = HTMLTag> = Polymorphic<{
as: Tag
variant: keyof typeof variantClasses
color: keyof typeof colorClasses
}> |
The documentation doesn't mention anything about requiring a default value. 🤔 https://docs.astro.build/en/guides/typescript/#polymorphic-type |
I should clarify, I meant that we should mention it. |
I felt this would be a cool idea cause it will help devs with type safety. |
Edit: In addition to adding a default value, you need to cast it with ---
import type { Polymorphic, HTMLTag } from "astro/types";
type Props<T extends HTMLTag = HTMLTag> = Polymorphic<{ as: T }>;
const { as: Tag = "div" as any, ...attrs } = Astro.props;
---
<Tag {...attrs}>
<slot />
</Tag> |
You are right, with the default value as is optional |
Astro Info
If this issue only occurs in one browser, which browser is a problem?
No response
Describe the Bug
Astro.props is type as any
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
The text was updated successfully, but these errors were encountered: