From 76d1ec101cc435e3429222c88e5c41116806747d Mon Sep 17 00:00:00 2001 From: jdecroock Date: Thu, 12 Oct 2023 15:47:41 +0200 Subject: [PATCH] fix vnode type coercion --- src/index.d.ts | 20 +++++++++----------- test/ts/VNode-test.tsx | 12 +++++++++--- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/index.d.ts b/src/index.d.ts index a2a881d2bb..e603afdb2b 100644 --- a/src/index.d.ts +++ b/src/index.d.ts @@ -195,9 +195,8 @@ export function createElement( | null, ...children: ComponentChildren[] ): VNode< - | (JSXInternal.DOMAttributes & - ClassAttributes) - | null + | JSXInternal.DOMAttributes & + ClassAttributes >; export function createElement< P extends JSXInternal.HTMLAttributes, @@ -206,7 +205,7 @@ export function createElement< type: keyof JSXInternal.IntrinsicElements, props: (ClassAttributes & P) | null, ...children: ComponentChildren[] -): VNode<(ClassAttributes & P) | null>; +): VNode & P>; export function createElement< P extends JSXInternal.SVGAttributes, T extends HTMLElement @@ -214,7 +213,7 @@ export function createElement< type: keyof JSXInternal.IntrinsicElements, props: (ClassAttributes & P) | null, ...children: ComponentChildren[] -): VNode<(ClassAttributes & P) | null>; +): VNode & P>; export function createElement( type: string, props: @@ -243,9 +242,8 @@ export function h( | null, ...children: ComponentChildren[] ): VNode< - | (JSXInternal.DOMAttributes & - ClassAttributes) - | null + | JSXInternal.DOMAttributes & + ClassAttributes >; export function h< P extends JSXInternal.HTMLAttributes, @@ -254,7 +252,7 @@ export function h< type: keyof JSXInternal.IntrinsicElements, props: (ClassAttributes & P) | null, ...children: ComponentChildren[] -): VNode<(ClassAttributes & P) | null>; +): VNode & P>; export function h< P extends JSXInternal.SVGAttributes, T extends HTMLElement @@ -262,7 +260,7 @@ export function h< type: keyof JSXInternal.IntrinsicElements, props: (ClassAttributes & P) | null, ...children: ComponentChildren[] -): VNode<(ClassAttributes & P) | null>; +): VNode & P>; export function h( type: string, props: @@ -281,7 +279,7 @@ export function h

( type: ComponentType

, props: (Attributes & P) | null, ...children: ComponentChildren[] -): VNode<(Attributes & P) | null>; +): VNode; export namespace h { export import JSX = JSXInternal; } diff --git a/test/ts/VNode-test.tsx b/test/ts/VNode-test.tsx index 722590184e..dd050d2e67 100644 --- a/test/ts/VNode-test.tsx +++ b/test/ts/VNode-test.tsx @@ -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 =

Hi!
; - expect(div.type).to.equal('div'); + it('is returned by h', () => { + const actual =
; + 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', () => {