-
Notifications
You must be signed in to change notification settings - Fork 30
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
RFC: Component interface #300
Conversation
Love this idea. The slots typing gets back to some awkwardness I've encountered: how do you accurately type slots and Elements in Astro? |
Admittedly, the slots typing part isn't really part of this RFC as much as this RFC unlocks at least room for a place to type slots 😛 |
Yes, just like the function Button(_props: Component.props): any |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love how this is coming together! Would we also be able to ship strict typing for props
if a user opts-into the new Component
interface?
I am not 100% sure if I get what you mean. If you mean typing If you mean making sure the shape of |
Love this @Princesseuh! Definitely has a nice migration story too: keep supporting |
@Princesseuh Would it be possible to add export to the Component interface? It'd make it clear that the interface is meant for outside leaning tools. e.g. /**
* @name Button
* Description
*
* @slot default - Default slot
* @slot button - Change the button
* @slot ...
*/
export interface Component {
// ...
} |
It'd work just like the current Props interface so exporting it would be left to the user's choice (it works either way) Personally, I think it's better to use normal rules for it and only export it when you actually need it in another file. But, I'm happy to support things either way! |
@Princesseuh What do you think about using |
I'd rather not introduce additional rules to normal JSDoc comments to avoid incompatibility with external tools such as documentation generators I think the format I'd recommend is a JSDoc comment on top of the actual definition of each slots - like you'd do for props right now. (Should be noted that typing slots and the syntax for them isn't really in the scope of this RFC, it was just meant as an example of how this can be extended) |
So, if I'm understanding you correctly, when a user has both e.g. /**
* ...
*/
interface Props {
...
}
/**
* ...
*/
interface Slots {
...
}
/**
* @name Component
* Description
*/
interface Components {
slots: Slots,
props: Props
} |
That is right. For retrocompatibility sake, if the Component interface didn't exist in your example, the Props one would be used |
I'd assume this means transitioning to the default type of Astro.props being Component.props instead of Props & {} i.e. not merging in the Record<string, any> type and requiring all props and slots to be explicit |
Summary
Introduces a new interface called "Component" that is used to describe components. This unlocks the following benefits:
Links