diff --git a/src/index.d.ts b/src/index.d.ts index e89a841193..93414cdaa1 100644 --- a/src/index.d.ts +++ b/src/index.d.ts @@ -188,11 +188,35 @@ export abstract class Component { // ----------------------------------- export function createElement( + type: 'input', + props: + | (JSXInternal.DOMAttributes & + ClassAttributes) + | null, + ...children: ComponentChildren[] +): VNode; +export function createElement< + P extends JSXInternal.HTMLAttributes, + T extends HTMLElement +>( + type: keyof JSXInternal.IntrinsicElements, + props: (ClassAttributes & P) | null, + ...children: ComponentChildren[] +): VNode; +export function createElement< + P extends JSXInternal.SVGAttributes, + T extends HTMLElement +>( + type: keyof JSXInternal.IntrinsicElements, + props: (ClassAttributes & P) | null, + ...children: ComponentChildren[] +): VNode; +export function createElement( type: string, props: - | (JSXInternal.HTMLAttributes & - JSXInternal.SVGAttributes & - Record) + | (ClassAttributes & + JSXInternal.HTMLAttributes & + JSXInternal.SVGAttributes) | null, ...children: ComponentChildren[] ): VNode; @@ -206,11 +230,35 @@ export namespace createElement { } export function h( + type: 'input', + props: + | (JSXInternal.DOMAttributes & + ClassAttributes) + | null, + ...children: ComponentChildren[] +): VNode; +export function h< + P extends JSXInternal.HTMLAttributes, + T extends HTMLElement +>( + type: keyof JSXInternal.IntrinsicElements, + props: (ClassAttributes & P) | null, + ...children: ComponentChildren[] +): VNode; +export function h< + P extends JSXInternal.SVGAttributes, + T extends HTMLElement +>( + type: keyof JSXInternal.IntrinsicElements, + props: (ClassAttributes & P) | null, + ...children: ComponentChildren[] +): VNode; +export function h( type: string, props: - | (JSXInternal.HTMLAttributes & - JSXInternal.SVGAttributes & - Record) + | (ClassAttributes & + JSXInternal.HTMLAttributes & + JSXInternal.SVGAttributes) | null, ...children: ComponentChildren[] ): VNode; diff --git a/test/ts/preact.tsx b/test/ts/preact.tsx index 26cd1a9cc7..9f13a2ab43 100644 --- a/test/ts/preact.tsx +++ b/test/ts/preact.tsx @@ -5,7 +5,8 @@ import { ComponentProps, FunctionalComponent, AnyComponent, - h + h, + createRef } from '../../'; interface DummyProps { @@ -314,3 +315,20 @@ const acceptsNumberAsLength =
; const acceptsStringAsLength =
; const ReturnNull: FunctionalComponent = () => null; + +// Refs should work on elements +const ref = createRef(); +createElement('div', { ref: ref }, 'hi'); +h('div', { ref: ref }, 'hi'); + +// Refs should work on functions +const functionRef = createRef(); +const RefComponentTest = () =>

hi

; +createElement(RefComponentTest, { ref: functionRef }, 'hi'); +h(RefComponentTest, { ref: functionRef }, 'hi'); + +// Should accept onInput +const onInput = (e: h.JSX.TargetedEvent) => {}; +; +createElement('input', { onInput: onInput }); +h('input', { onInput: onInput });