mirror of
https://github.com/withastro/astro.git
synced 2024-12-23 21:53:55 -05:00
Add astro/types
for common prop patterns (#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 <nate@astro.build>
This commit is contained in:
parent
0408376281
commit
0bf0758fb8
3 changed files with 28 additions and 0 deletions
16
.changeset/dirty-cycles-lick.md
Normal file
16
.changeset/dirty-cycles-lick.md
Normal file
|
@ -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;
|
||||||
|
};
|
||||||
|
```
|
|
@ -29,6 +29,7 @@
|
||||||
"default": "./astro.js"
|
"default": "./astro.js"
|
||||||
},
|
},
|
||||||
"./env": "./env.d.ts",
|
"./env": "./env.d.ts",
|
||||||
|
"./types": "./types.d.ts",
|
||||||
"./client": "./client.d.ts",
|
"./client": "./client.d.ts",
|
||||||
"./client-base": "./client-base.d.ts",
|
"./client-base": "./client-base.d.ts",
|
||||||
"./import-meta": "./import-meta.d.ts",
|
"./import-meta": "./import-meta.d.ts",
|
||||||
|
|
11
packages/astro/types.d.ts
vendored
Normal file
11
packages/astro/types.d.ts
vendored
Normal file
|
@ -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']>}>;
|
Loading…
Reference in a new issue