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:
parent
cddbec4619
commit
58f9e393a1
2 changed files with 18 additions and 1 deletions
14
.changeset/cuddly-moons-hang.md
Normal file
14
.changeset/cuddly-moons-hang.md
Normal 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>;
|
||||
---
|
||||
```
|
5
packages/astro/types.d.ts
vendored
5
packages/astro/types.d.ts
vendored
|
@ -1,5 +1,6 @@
|
|||
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 */
|
||||
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<
|
||||
Omit<P, 'as'> & { as: NonNullable<P['as']> }
|
||||
>;
|
||||
|
||||
export type ComponentProps<T extends (args: any) => any> = Simplify<Parameters<T>[0]>;
|
||||
|
|
Loading…
Reference in a new issue