From 4f26835dac5c345e6ccb2e2c2844f3560daa1de3 Mon Sep 17 00:00:00 2001 From: Kael Date: Tue, 30 Mar 2021 08:38:25 +1100 Subject: [PATCH] fix(types/tsx): make JSX.Element extend VNode (#3171) --- packages/runtime-core/src/h.ts | 12 ++++++++++++ packages/runtime-dom/types/jsx.d.ts | 3 ++- test-dts/functionalComponent.test-d.tsx | 4 +++- test-dts/tsx.test-d.tsx | 4 +++- 4 files changed, 20 insertions(+), 3 deletions(-) diff --git a/packages/runtime-core/src/h.ts b/packages/runtime-core/src/h.ts index cb87cf6e..f22e4bb3 100644 --- a/packages/runtime-core/src/h.ts +++ b/packages/runtime-core/src/h.ts @@ -4,6 +4,8 @@ import { createVNode, VNodeArrayChildren, Fragment, + Text, + Comment, isVNode } from './vnode' import { Teleport, TeleportProps } from './components/Teleport' @@ -84,6 +86,16 @@ export function h( children?: RawChildren | RawSlots ): VNode +// text/comment +export function h( + type: typeof Text | typeof Comment, + children?: string | number | boolean +): VNode +export function h( + type: typeof Text | typeof Comment, + props?: null, + children?: string | number | boolean +): VNode // fragment export function h(type: typeof Fragment, children?: VNodeArrayChildren): VNode export function h( diff --git a/packages/runtime-dom/types/jsx.d.ts b/packages/runtime-dom/types/jsx.d.ts index 729f8f59..cd4133a9 100644 --- a/packages/runtime-dom/types/jsx.d.ts +++ b/packages/runtime-dom/types/jsx.d.ts @@ -26,6 +26,7 @@ // Kanitkorn Sujautra // Sebastian Silbermann +import { VNode } from '@vue/runtime-core' import * as CSS from 'csstype' export interface CSSProperties extends CSS.Properties { @@ -1338,7 +1339,7 @@ type NativeElements = { declare global { namespace JSX { - interface Element {} + interface Element extends VNode {} interface ElementClass { $props: {} } diff --git a/test-dts/functionalComponent.test-d.tsx b/test-dts/functionalComponent.test-d.tsx index 4fe4db64..fdcf346f 100644 --- a/test-dts/functionalComponent.test-d.tsx +++ b/test-dts/functionalComponent.test-d.tsx @@ -1,4 +1,6 @@ import { + h, + Text, FunctionalComponent, expectError, expectType, @@ -6,7 +8,7 @@ import { } from './index' // simple function signature -const Foo = (props: { foo: number }) => props.foo +const Foo = (props: { foo: number }) => h(Text, null, props.foo) // TSX expectType() diff --git a/test-dts/tsx.test-d.tsx b/test-dts/tsx.test-d.tsx index d1bacc9d..ce1aec82 100644 --- a/test-dts/tsx.test-d.tsx +++ b/test-dts/tsx.test-d.tsx @@ -5,9 +5,11 @@ import { Fragment, Teleport, expectError, - expectType + expectType, + VNode } from './index' +expectType(
) expectType(
) expectType(
) expectType()