From cf6942dc229dcb16d8257a6aa01e7d4d673da58f Mon Sep 17 00:00:00 2001 From: Ryan Christian <33403762+rschristian@users.noreply.github.com> Date: Fri, 29 Nov 2024 01:12:57 -0600 Subject: [PATCH] fix: `createElement` & `h` types (#4578) * fix: createElement & h types * test: Add type tests * chore: Backport fix to TS 5.0 types too --- src/index-5.d.ts | 4 ++-- src/index.d.ts | 8 ++++---- test/ts/preact.tsx | 3 +++ 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/index-5.d.ts b/src/index-5.d.ts index a2be9f081f..7311010d71 100644 --- a/src/index-5.d.ts +++ b/src/index-5.d.ts @@ -226,7 +226,7 @@ export function createElement( ClassAttributes & JSXInternal.HTMLAttributes & JSXInternal.SVGAttributes >; export function createElement

( - type: ComponentType

, + type: ComponentType

| string, props: (Attributes & P) | null, ...children: ComponentChildren[] ): VNode

; @@ -276,7 +276,7 @@ export function h( | null >; export function h

( - type: ComponentType

, + type: ComponentType

| string, props: (Attributes & P) | null, ...children: ComponentChildren[] ): VNode; diff --git a/src/index.d.ts b/src/index.d.ts index fb868f3b17..279af93ab2 100644 --- a/src/index.d.ts +++ b/src/index.d.ts @@ -210,7 +210,7 @@ export function createElement< P extends JSXInternal.SVGAttributes, T extends HTMLElement >( - type: keyof JSXInternal.IntrinsicElements, + type: keyof JSXInternal.IntrinsicSVGElements, props: (ClassAttributes & P) | null, ...children: ComponentChildren[] ): VNode & P>; @@ -226,7 +226,7 @@ export function createElement( ClassAttributes & JSXInternal.HTMLAttributes & JSXInternal.SVGAttributes >; export function createElement

( - type: ComponentType

, + type: ComponentType

| string, props: (Attributes & P) | null, ...children: ComponentChildren[] ): VNode

; @@ -257,7 +257,7 @@ export function h< P extends JSXInternal.SVGAttributes, T extends HTMLElement >( - type: keyof JSXInternal.IntrinsicElements, + type: keyof JSXInternal.IntrinsicSVGElements, props: (ClassAttributes & P) | null, ...children: ComponentChildren[] ): VNode & P>; @@ -276,7 +276,7 @@ export function h( | null >; export function h

( - type: ComponentType

, + type: ComponentType

| string, props: (Attributes & P) | null, ...children: ComponentChildren[] ): VNode; diff --git a/test/ts/preact.tsx b/test/ts/preact.tsx index ef647eeb9d..43d88336ff 100644 --- a/test/ts/preact.tsx +++ b/test/ts/preact.tsx @@ -378,3 +378,6 @@ const onSubmit = (e: h.JSX.TargetedSubmitEvent) => {};

e.currentTarget.elements} />; createElement('form', { onSubmit: onSubmit }); h('form', { onSubmit: onSubmit }); + +h('option', { value: 'foo' }); +createElement('option', { value: 'foo' });