mirror of
https://github.com/withastro/astro.git
synced 2025-01-27 22:19:04 -05:00
fix(types): Omit data types from polymorphic attributes (#10593)
* fix(types): Omit data types from polymorphic attributes * chore: changeset
This commit is contained in:
parent
9b08facb27
commit
61e283e5a0
2 changed files with 13 additions and 3 deletions
5
.changeset/khaki-ties-carry.md
Normal file
5
.changeset/khaki-ties-carry.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
"astro": patch
|
||||
---
|
||||
|
||||
Fixes Polymorphic type helper causing TypeScript errors in certain cases after the previous update
|
11
packages/astro/types.d.ts
vendored
11
packages/astro/types.d.ts
vendored
|
@ -1,13 +1,13 @@
|
|||
import './astro-jsx';
|
||||
import type { AstroBuiltinAttributes } from './dist/@types/astro.js';
|
||||
import type { Simplify } from './dist/type-utils.js';
|
||||
import type { OmitIndexSignature, 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;
|
||||
|
||||
/** The built-in attributes for any known HTML or SVG element name */
|
||||
export type HTMLAttributes<Tag extends HTMLTag> = Omit<
|
||||
astroHTML.JSX.IntrinsicElements[Tag],
|
||||
astroHTML.JSX.DefinedIntrinsicElements[Tag],
|
||||
keyof Omit<AstroBuiltinAttributes, 'class:list'>
|
||||
>;
|
||||
|
||||
|
@ -18,7 +18,12 @@ export type CSSProperty = keyof astroHTML.JSX.KebabCSSDOMProperties;
|
|||
|
||||
type PolymorphicAttributes<P extends { as: HTMLTag }> = Omit<P, 'as'> & {
|
||||
as?: P['as'];
|
||||
} & HTMLAttributes<P['as']>;
|
||||
} & Omit<
|
||||
// This is the same as HTMLAttributes<P['as']>, except we're using OmitIndexSignature to remove the index signature,
|
||||
// used for data attribute, because it seems like it get too complex for TypeScript with it, not sure why.
|
||||
OmitIndexSignature<astroHTML.JSX.DefinedIntrinsicElements[P['as']]>,
|
||||
keyof Omit<AstroBuiltinAttributes, 'class:list'>
|
||||
>;
|
||||
|
||||
export type Polymorphic<P extends { as: HTMLTag }> = PolymorphicAttributes<
|
||||
Omit<P, 'as'> & { as: NonNullable<P['as']> }
|
||||
|
|
Loading…
Add table
Reference in a new issue