summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Erika <3019731+Princesseuh@users.noreply.github.com> 2023-05-17 15:38:27 +0200
committerGravatar GitHub <noreply@github.com> 2023-05-17 15:38:27 +0200
commitc1669c0011eecfe65a459d727848c18c189a54ca (patch)
tree3442c7a5e30334b982595d615394c222f80939bc
parentdd8dd6b31e13502ee140a4706dcd85d92b69c563 (diff)
downloadastro-c1669c0011eecfe65a459d727848c18c189a54ca.tar.gz
astro-c1669c0011eecfe65a459d727848c18c189a54ca.tar.zst
astro-c1669c0011eecfe65a459d727848c18c189a54ca.zip
feat: uncomment polymorphic type (#7069)
-rw-r--r--.changeset/two-carrots-smile.md17
-rw-r--r--packages/astro/types.d.ts9
2 files changed, 23 insertions, 3 deletions
diff --git a/.changeset/two-carrots-smile.md b/.changeset/two-carrots-smile.md
new file mode 100644
index 000000000..d5b046b0b
--- /dev/null
+++ b/.changeset/two-carrots-smile.md
@@ -0,0 +1,17 @@
+---
+'astro': minor
+---
+
+Added `Polymorphic` type helper to `astro/types` to easily create polymorphic components:
+
+```astro
+---
+import { HTMLTag, Polymorphic } from 'astro/types';
+
+type Props<Tag extends HTMLTag> = Polymorphic<{ as: Tag }>;
+
+const { as: Tag, ...props } = Astro.props;
+---
+
+<Tag {...props} />
+```
diff --git a/packages/astro/types.d.ts b/packages/astro/types.d.ts
index a8ad0267b..0939c828a 100644
--- a/packages/astro/types.d.ts
+++ b/packages/astro/types.d.ts
@@ -9,6 +9,9 @@ export type HTMLAttributes<Tag extends HTMLTag> = Omit<
keyof Omit<AstroBuiltinAttributes, 'class:list'>
>;
-// TODO: Enable generic/polymorphic types once compiler output stabilizes in the Language Server
-// type PolymorphicAttributes<P extends { as: HTMLTag }> = Omit<(P & HTMLAttributes<P['as']>), 'as'> & { as?: P['as'] };
-// export type Polymorphic<P extends { as: HTMLTag }> = PolymorphicAttributes<Omit<P, 'as'> & { as: NonNullable<P['as']>}>;
+type PolymorphicAttributes<P extends { as: HTMLTag }> = Omit<P & HTMLAttributes<P['as']>, 'as'> & {
+ as?: P['as'];
+};
+export type Polymorphic<P extends { as: HTMLTag }> = PolymorphicAttributes<
+ Omit<P, 'as'> & { as: NonNullable<P['as']> }
+>;