Skip to content

Commit

Permalink
fix vnode type coercion (#4158)
Browse files Browse the repository at this point in the history
  • Loading branch information
JoviDeCroock committed Oct 15, 2023
1 parent 4b1a7e9 commit 19de3d9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
20 changes: 9 additions & 11 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,8 @@ export function createElement(
| null,
...children: ComponentChildren[]
): VNode<
| (JSXInternal.DOMAttributes<HTMLInputElement> &
ClassAttributes<HTMLInputElement>)
| null
| JSXInternal.DOMAttributes<HTMLInputElement> &
ClassAttributes<HTMLInputElement>
>;
export function createElement<
P extends JSXInternal.HTMLAttributes<T>,
Expand All @@ -206,15 +205,15 @@ export function createElement<
type: keyof JSXInternal.IntrinsicElements,
props: (ClassAttributes<T> & P) | null,
...children: ComponentChildren[]
): VNode<(ClassAttributes<T> & P) | null>;
): VNode<ClassAttributes<T> & P>;
export function createElement<
P extends JSXInternal.SVGAttributes<T>,
T extends HTMLElement
>(
type: keyof JSXInternal.IntrinsicElements,
props: (ClassAttributes<T> & P) | null,
...children: ComponentChildren[]
): VNode<(ClassAttributes<T> & P) | null>;
): VNode<ClassAttributes<T> & P>;
export function createElement<T extends HTMLElement>(
type: string,
props:
Expand Down Expand Up @@ -243,9 +242,8 @@ export function h(
| null,
...children: ComponentChildren[]
): VNode<
| (JSXInternal.DOMAttributes<HTMLInputElement> &
ClassAttributes<HTMLInputElement>)
| null
| JSXInternal.DOMAttributes<HTMLInputElement> &
ClassAttributes<HTMLInputElement>
>;
export function h<
P extends JSXInternal.HTMLAttributes<T>,
Expand All @@ -254,15 +252,15 @@ export function h<
type: keyof JSXInternal.IntrinsicElements,
props: (ClassAttributes<T> & P) | null,
...children: ComponentChildren[]
): VNode<(ClassAttributes<T> & P) | null>;
): VNode<ClassAttributes<T> & P>;
export function h<
P extends JSXInternal.SVGAttributes<T>,
T extends HTMLElement
>(
type: keyof JSXInternal.IntrinsicElements,
props: (ClassAttributes<T> & P) | null,
...children: ComponentChildren[]
): VNode<(ClassAttributes<T> & P) | null>;
): VNode<ClassAttributes<T> & P>;
export function h<T extends HTMLElement>(
type: string,
props:
Expand All @@ -281,7 +279,7 @@ export function h<P>(
type: ComponentType<P>,
props: (Attributes & P) | null,
...children: ComponentChildren[]
): VNode<(Attributes & P) | null>;
): VNode<Attributes & P>;
export namespace h {
export import JSX = JSXInternal;
}
Expand Down
12 changes: 9 additions & 3 deletions test/ts/VNode-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,15 @@ describe('VNode TS types', () => {
expect(actual).to.include.all.keys('type', 'props', 'key');
});

it('has a nodeName of string when html element', () => {
const div = <div>Hi!</div>;
expect(div.type).to.equal('div');
it('is returned by h', () => {
const actual = <div className="wow" />;
expect(actual).to.include.all.keys('type', 'props', 'key');
});

it('createElement conforms to the VNode type', () => {
const arr: VNode[] = [];
arr.push(createElement('div', null));
expect(true).to.be.true;
});

it('has a nodeName equal to the construction function when SFC', () => {
Expand Down

0 comments on commit 19de3d9

Please sign in to comment.