From dfb6c32d139b309264c052fd273043f8dc9d62ff 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 | 9 ++++----- test/ts/VNode-test.tsx | 12 +++++++++--- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/index.d.ts b/src/index.d.ts index a2a881d2bbd..6faf4726d47 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: diff --git a/test/ts/VNode-test.tsx b/test/ts/VNode-test.tsx index 722590184ec..dd050d2e67e 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', () => {