File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ ---
2+ ' astro ' : minor
3+ ---
4+
5+ Added ` Polymorphic ` type helper to ` astro/types ` to easily create polymorphic components:
6+
7+ ``` astro
8+ ---
9+ import { HTMLTag, Polymorphic } from 'astro/types';
10+
11+ type Props<Tag extends HTMLTag> = Polymorphic<{ as: Tag }>;
12+
13+ const { as: Tag, ...props } = Astro.props;
14+ ---
15+
16+ <Tag {...props} />
17+ ```
Original file line number Diff line number Diff line change @@ -9,6 +9,9 @@ export type HTMLAttributes<Tag extends HTMLTag> = Omit<
99 keyof Omit < AstroBuiltinAttributes , 'class:list' >
1010> ;
1111
12- // TODO: Enable generic/polymorphic types once compiler output stabilizes in the Language Server
13- // type PolymorphicAttributes<P extends { as: HTMLTag }> = Omit<(P & HTMLAttributes<P['as']>), 'as'> & { as?: P['as'] };
14- // export type Polymorphic<P extends { as: HTMLTag }> = PolymorphicAttributes<Omit<P, 'as'> & { as: NonNullable<P['as']>}>;
12+ type PolymorphicAttributes < P extends { as : HTMLTag } > = Omit < P & HTMLAttributes < P [ 'as' ] > , 'as' > & {
13+ as ?: P [ 'as' ] ;
14+ } ;
15+ export type Polymorphic < P extends { as : HTMLTag } > = PolymorphicAttributes <
16+ Omit < P , 'as' > & { as : NonNullable < P [ 'as' ] > }
17+ > ;
You can’t perform that action at this time.
0 commit comments