Skip to content

Commit 4f26835

Browse files
authored
fix(types/tsx): make JSX.Element extend VNode (#3171)
1 parent d090452 commit 4f26835

File tree

4 files changed

+20
-3
lines changed

4 files changed

+20
-3
lines changed

packages/runtime-core/src/h.ts

+12
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import {
44
createVNode,
55
VNodeArrayChildren,
66
Fragment,
7+
Text,
8+
Comment,
79
isVNode
810
} from './vnode'
911
import { Teleport, TeleportProps } from './components/Teleport'
@@ -84,6 +86,16 @@ export function h(
8486
children?: RawChildren | RawSlots
8587
): VNode
8688

89+
// text/comment
90+
export function h(
91+
type: typeof Text | typeof Comment,
92+
children?: string | number | boolean
93+
): VNode
94+
export function h(
95+
type: typeof Text | typeof Comment,
96+
props?: null,
97+
children?: string | number | boolean
98+
): VNode
8799
// fragment
88100
export function h(type: typeof Fragment, children?: VNodeArrayChildren): VNode
89101
export function h(

packages/runtime-dom/types/jsx.d.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
// Kanitkorn Sujautra <https://github.com/lukyth>
2727
// Sebastian Silbermann <https://github.com/eps1lon>
2828

29+
import { VNode } from '@vue/runtime-core'
2930
import * as CSS from 'csstype'
3031

3132
export interface CSSProperties extends CSS.Properties<string | number> {
@@ -1338,7 +1339,7 @@ type NativeElements = {
13381339

13391340
declare global {
13401341
namespace JSX {
1341-
interface Element {}
1342+
interface Element extends VNode {}
13421343
interface ElementClass {
13431344
$props: {}
13441345
}

test-dts/functionalComponent.test-d.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import {
2+
h,
3+
Text,
24
FunctionalComponent,
35
expectError,
46
expectType,
57
Component
68
} from './index'
79

810
// simple function signature
9-
const Foo = (props: { foo: number }) => props.foo
11+
const Foo = (props: { foo: number }) => h(Text, null, props.foo)
1012

1113
// TSX
1214
expectType<JSX.Element>(<Foo foo={1} />)

test-dts/tsx.test-d.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@ import {
55
Fragment,
66
Teleport,
77
expectError,
8-
expectType
8+
expectType,
9+
VNode
910
} from './index'
1011

12+
expectType<VNode>(<div />)
1113
expectType<JSX.Element>(<div />)
1214
expectType<JSX.Element>(<div id="foo" />)
1315
expectType<JSX.Element>(<input value="foo" />)

0 commit comments

Comments
 (0)