]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(types/tsx): make JSX.Element extend VNode (#3171)
authorKael <kaelwd@gmail.com>
Mon, 29 Mar 2021 21:38:25 +0000 (08:38 +1100)
committerGitHub <noreply@github.com>
Mon, 29 Mar 2021 21:38:25 +0000 (17:38 -0400)
packages/runtime-core/src/h.ts
packages/runtime-dom/types/jsx.d.ts
test-dts/functionalComponent.test-d.tsx
test-dts/tsx.test-d.tsx

index cb87cf6ee3c520efe71a12a0b502bbd2d5c0636a..f22e4bb30d06d3195a82abcf2cec0b2478aab079 100644 (file)
@@ -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(
index 729f8f593fc5d38054a5785b596c45faa542d56c..cd4133a9af1d3bc56f3770cf70da321870787960 100644 (file)
@@ -26,6 +26,7 @@
 //                 Kanitkorn Sujautra <https://github.com/lukyth>
 //                 Sebastian Silbermann <https://github.com/eps1lon>
 
+import { VNode } from '@vue/runtime-core'
 import * as CSS from 'csstype'
 
 export interface CSSProperties extends CSS.Properties<string | number> {
@@ -1338,7 +1339,7 @@ type NativeElements = {
 
 declare global {
   namespace JSX {
-    interface Element {}
+    interface Element extends VNode {}
     interface ElementClass {
       $props: {}
     }
index 4fe4db645afd77f4cadda7055f28be50748d0deb..fdcf346fb703f1979a01969bee9308893bce7fb8 100644 (file)
@@ -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<JSX.Element>(<Foo foo={1} />)
index d1bacc9d73509335bb2d3b05741038e1ed60c7b6..ce1aec82043a07debe59eb6bf3aa59b951bca9a6 100644 (file)
@@ -5,9 +5,11 @@ import {
   Fragment,
   Teleport,
   expectError,
-  expectType
+  expectType,
+  VNode
 } from './index'
 
+expectType<VNode>(<div />)
 expectType<JSX.Element>(<div />)
 expectType<JSX.Element>(<div id="foo" />)
 expectType<JSX.Element>(<input value="foo" />)