Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(types): Omit data types from polymorphic attributes #10593

Merged
merged 2 commits into from
Mar 28, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions packages/astro/types.d.ts
Original file line number Diff line number Diff line change
@@ -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'>
>;

Expand All @@ -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']> }
Expand Down
Loading