diff --git a/.changeset/dirty-cycles-lick.md b/.changeset/dirty-cycles-lick.md new file mode 100644 index 000000000..e8e39be9b --- /dev/null +++ b/.changeset/dirty-cycles-lick.md @@ -0,0 +1,16 @@ +--- +'astro': minor +--- + +Add `astro/types` entrypoint. These utilities can be used for common prop type patterns. + +## `HTMLAttributes` + +If you would like to extend valid HTML attributes for a given HTML element, you may use the provided `HTMLAttributes` type—it accepts an element name and returns the valid HTML attributes for that element name. + +```ts +import { HTMLAttributes } from 'astro/types'; +interface Props extends HTMLAttributes<'a'> { + myProp?: string; +}; +``` diff --git a/packages/astro/package.json b/packages/astro/package.json index 527a87e1a..331ef6b27 100644 --- a/packages/astro/package.json +++ b/packages/astro/package.json @@ -29,6 +29,7 @@ "default": "./astro.js" }, "./env": "./env.d.ts", + "./types": "./types.d.ts", "./client": "./client.d.ts", "./client-base": "./client-base.d.ts", "./import-meta": "./import-meta.d.ts", diff --git a/packages/astro/types.d.ts b/packages/astro/types.d.ts new file mode 100644 index 000000000..ae56cd2dc --- /dev/null +++ b/packages/astro/types.d.ts @@ -0,0 +1,11 @@ +import './astro-jsx'; +import { AstroBuiltinAttributes } from './dist/@types/astro'; + +/** Any supported HTML or SVG element name, as defined by the HTML specification */ +export type HTMLTag = keyof astroHTML.JSX.DefinedIntrinsicElements; +/** The built-in attributes for any known HTML or SVG element name */ +export type HTMLAttributes = Omit; + +// TODO: Enable generic/polymorphic types once compiler output stabilizes in the Language Server +// type PolymorphicAttributes

= Omit<(P & HTMLAttributes), 'as'> & { as?: P['as'] }; +// export type Polymorphic

= PolymorphicAttributes & { as: NonNullable}>;