Skip to content

Commit

Permalink
improve VNode typings when generic is passed in (#4050)
Browse files Browse the repository at this point in the history
  • Loading branch information
JoviDeCroock authored Jun 25, 2023
1 parent 56d8f41 commit 0ef740b
Showing 1 changed file with 25 additions and 10 deletions.
35 changes: 25 additions & 10 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,23 +194,27 @@ export function createElement(
ClassAttributes<HTMLInputElement>)
| null,
...children: ComponentChildren[]
): VNode<any>;
): VNode<
| (JSXInternal.DOMAttributes<HTMLInputElement> &
ClassAttributes<HTMLInputElement>)
| null
>;
export function createElement<
P extends JSXInternal.HTMLAttributes<T>,
T extends HTMLElement
>(
type: keyof JSXInternal.IntrinsicElements,
props: (ClassAttributes<T> & P) | null,
...children: ComponentChildren[]
): VNode<any>;
): VNode<(ClassAttributes<T> & P) | null>;
export function createElement<
P extends JSXInternal.SVGAttributes<T>,
T extends HTMLElement
>(
type: keyof JSXInternal.IntrinsicElements,
props: (ClassAttributes<T> & P) | null,
...children: ComponentChildren[]
): VNode<any>;
): VNode<(ClassAttributes<T> & P) | null>;
export function createElement<T extends HTMLElement>(
type: string,
props:
Expand All @@ -219,12 +223,14 @@ export function createElement<T extends HTMLElement>(
JSXInternal.SVGAttributes)
| null,
...children: ComponentChildren[]
): VNode<any>;
): VNode<
ClassAttributes<T> & JSXInternal.HTMLAttributes & JSXInternal.SVGAttributes
>;
export function createElement<P>(
type: ComponentType<P>,
props: (Attributes & P) | null,
...children: ComponentChildren[]
): VNode<any>;
): VNode<P>;
export namespace createElement {
export import JSX = JSXInternal;
}
Expand All @@ -236,23 +242,27 @@ export function h(
ClassAttributes<HTMLInputElement>)
| null,
...children: ComponentChildren[]
): VNode<any>;
): VNode<
| (JSXInternal.DOMAttributes<HTMLInputElement> &
ClassAttributes<HTMLInputElement>)
| null
>;
export function h<
P extends JSXInternal.HTMLAttributes<T>,
T extends HTMLElement
>(
type: keyof JSXInternal.IntrinsicElements,
props: (ClassAttributes<T> & P) | null,
...children: ComponentChildren[]
): VNode<any>;
): VNode<(ClassAttributes<T> & P) | null>;
export function h<
P extends JSXInternal.SVGAttributes<T>,
T extends HTMLElement
>(
type: keyof JSXInternal.IntrinsicElements,
props: (ClassAttributes<T> & P) | null,
...children: ComponentChildren[]
): VNode<any>;
): VNode<(ClassAttributes<T> & P) | null>;
export function h<T extends HTMLElement>(
type: string,
props:
Expand All @@ -261,12 +271,17 @@ export function h<T extends HTMLElement>(
JSXInternal.SVGAttributes)
| null,
...children: ComponentChildren[]
): VNode<any>;
): VNode<
| (ClassAttributes<T> &
JSXInternal.HTMLAttributes &
JSXInternal.SVGAttributes)
| null
>;
export function h<P>(
type: ComponentType<P>,
props: (Attributes & P) | null,
...children: ComponentChildren[]
): VNode<any>;
): VNode<(Attributes & P) | null>;
export namespace h {
export import JSX = JSXInternal;
}
Expand Down

0 comments on commit 0ef740b

Please sign in to comment.