Skip to content
New issue

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

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

Already on GitHub? # to your account

fix: createElement & h types #4578

Merged
merged 3 commits into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions src/index-5.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ export function createElement<T extends HTMLElement>(
ClassAttributes<T> & JSXInternal.HTMLAttributes & JSXInternal.SVGAttributes
>;
export function createElement<P>(
type: ComponentType<P>,
type: ComponentType<P> | string,
props: (Attributes & P) | null,
...children: ComponentChildren[]
): VNode<P>;
Expand Down Expand Up @@ -276,7 +276,7 @@ export function h<T extends HTMLElement>(
| null
>;
export function h<P>(
type: ComponentType<P>,
type: ComponentType<P> | string,
props: (Attributes & P) | null,
...children: ComponentChildren[]
): VNode<Attributes & P>;
Expand Down
8 changes: 4 additions & 4 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ export function createElement<
P extends JSXInternal.SVGAttributes<T>,
T extends HTMLElement
>(
type: keyof JSXInternal.IntrinsicElements,
type: keyof JSXInternal.IntrinsicSVGElements,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, drive-by change.

I couldn't find a situation in which this actually made a difference, as createElement/h seemingly always falls back to a very loose overload that allows anything, but we extracted out IntrinsicSVGElements a bit more than a year ago and so we should be using it.

props: (ClassAttributes<T> & P) | null,
...children: ComponentChildren[]
): VNode<ClassAttributes<T> & P>;
Expand All @@ -226,7 +226,7 @@ export function createElement<T extends HTMLElement>(
ClassAttributes<T> & JSXInternal.HTMLAttributes & JSXInternal.SVGAttributes
>;
export function createElement<P>(
type: ComponentType<P>,
type: ComponentType<P> | string,
props: (Attributes & P) | null,
...children: ComponentChildren[]
): VNode<P>;
Expand Down Expand Up @@ -257,7 +257,7 @@ export function h<
P extends JSXInternal.SVGAttributes<T>,
T extends HTMLElement
>(
type: keyof JSXInternal.IntrinsicElements,
type: keyof JSXInternal.IntrinsicSVGElements,
props: (ClassAttributes<T> & P) | null,
...children: ComponentChildren[]
): VNode<ClassAttributes<T> & P>;
Expand All @@ -276,7 +276,7 @@ export function h<T extends HTMLElement>(
| null
>;
export function h<P>(
type: ComponentType<P>,
type: ComponentType<P> | string,
props: (Attributes & P) | null,
...children: ComponentChildren[]
): VNode<Attributes & P>;
Expand Down
3 changes: 3 additions & 0 deletions test/ts/preact.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -378,3 +378,6 @@ const onSubmit = (e: h.JSX.TargetedSubmitEvent<HTMLFormElement>) => {};
<form onSubmit={e => e.currentTarget.elements} />;
createElement('form', { onSubmit: onSubmit });
h('form', { onSubmit: onSubmit });

h('option', { value: 'foo' });
createElement('option', { value: 'foo' });