Use case for generic components #695
Labels
core
Processing and transforming logic
discussion
Ongoing conversation
feature
New syntax feature or behavior
types
Typing related
For example a base
Card
component that renders a provided content component part alongside a title. In runtime the actual provided component can be anything or restricted according to static typing or runtime validation.In Stylable, currently not specifying the
-st-extends
is equivalent to a part withany
type - It's an "Element" and there is no way of defining a generic type:I would like to suggest a generic syntax to restrict types:
In the example, the card stylesheet declares a generic type T that can be used in it's internal parts or even on the root element.
An example of targeting might select the
playBtn
of the content video component:I think that the generics should add to the specificity:
Complexities:
Multiple generic types:
-st-generics: T, U
Default type
Extend generic component
Maybe?:
Complex types
In Stylable a component is always a specific type, there is no concept of union type. We might want to add a way to describe multiple types for generics. For example the
MediaCard
component that "extends" theCard
component might want to restrict the content type:If Stylable is not going to provide real union type support, then this is just restricting the options that can be inserted into the generic selector. Not providing union type checking and completions.
The text was updated successfully, but these errors were encountered: