0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-23 21:53:55 -05:00

Add ComponentProps util (#9839)

* chore: changeset

* Update .changeset/cuddly-moons-hang.md

Co-authored-by: Nate Moore <natemoo-re@users.noreply.github.com>

---------

Co-authored-by: Nate Moore <natemoo-re@users.noreply.github.com>
This commit is contained in:
Erika 2024-01-31 14:56:44 +01:00 committed by GitHub
parent cddbec4619
commit 58f9e393a1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 18 additions and 1 deletions

View file

@ -0,0 +1,14 @@
---
"astro": minor
---
Adds a new `ComponentProps` type export from `astro/types` to get the props type of an Astro component.
```astro
---
import type { ComponentProps } from 'astro/types';
import { Button } from "./Button.astro";
type myButtonProps = ComponentProps<typeof Button>;
---
```

View file

@ -1,5 +1,6 @@
import './astro-jsx'; import './astro-jsx';
import { AstroBuiltinAttributes } from './dist/@types/astro.js'; import type { AstroBuiltinAttributes } from './dist/@types/astro.js';
import type { Simplify } from './dist/type-utils.js';
/** Any supported HTML or SVG element name, as defined by the HTML specification */ /** Any supported HTML or SVG element name, as defined by the HTML specification */
export type HTMLTag = keyof astroHTML.JSX.DefinedIntrinsicElements; export type HTMLTag = keyof astroHTML.JSX.DefinedIntrinsicElements;
@ -20,3 +21,5 @@ type PolymorphicAttributes<P extends { as: HTMLTag }> = Omit<P & HTMLAttributes<
export type Polymorphic<P extends { as: HTMLTag }> = PolymorphicAttributes< export type Polymorphic<P extends { as: HTMLTag }> = PolymorphicAttributes<
Omit<P, 'as'> & { as: NonNullable<P['as']> } Omit<P, 'as'> & { as: NonNullable<P['as']> }
>; >;
export type ComponentProps<T extends (args: any) => any> = Simplify<Parameters<T>[0]>;