Skip to content

Commit

Permalink
fix: createElement & h types (#4578)
Browse files Browse the repository at this point in the history
* fix: createElement & h types

* test: Add type tests

* chore: Backport fix to TS 5.0 types too
  • Loading branch information
rschristian authored Nov 29, 2024
1 parent db47ab6 commit cf6942d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
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,
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' });

0 comments on commit cf6942d

Please # to comment.