forked from withastro/astro
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
astro/types
for common prop patterns (withastro#5147)
* wip: add type-utils * feat: update type-utils * feat: RequireDefaultSlot => WithChildren * chore: add changeset * chore: move types to ./types * chore: update changeset * Update dirty-cycles-lick.md Co-authored-by: Nate Moore <[email protected]>
- Loading branch information
1 parent
0408376
commit 0bf0758
Showing
3 changed files
with
28 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
}; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Tag extends HTMLTag> = Omit<astroHTML.JSX.IntrinsicElements[Tag], keyof AstroBuiltinAttributes>; | ||
|
||
// 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']>}>; |