fix(types/tsx): make JSX.Element extend VNode (#3171)
This commit is contained in:
parent
d09045282c
commit
4f26835dac
@ -4,6 +4,8 @@ import {
|
|||||||
createVNode,
|
createVNode,
|
||||||
VNodeArrayChildren,
|
VNodeArrayChildren,
|
||||||
Fragment,
|
Fragment,
|
||||||
|
Text,
|
||||||
|
Comment,
|
||||||
isVNode
|
isVNode
|
||||||
} from './vnode'
|
} from './vnode'
|
||||||
import { Teleport, TeleportProps } from './components/Teleport'
|
import { Teleport, TeleportProps } from './components/Teleport'
|
||||||
@ -84,6 +86,16 @@ export function h(
|
|||||||
children?: RawChildren | RawSlots
|
children?: RawChildren | RawSlots
|
||||||
): VNode
|
): 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
|
// fragment
|
||||||
export function h(type: typeof Fragment, children?: VNodeArrayChildren): VNode
|
export function h(type: typeof Fragment, children?: VNodeArrayChildren): VNode
|
||||||
export function h(
|
export function h(
|
||||||
|
3
packages/runtime-dom/types/jsx.d.ts
vendored
3
packages/runtime-dom/types/jsx.d.ts
vendored
@ -26,6 +26,7 @@
|
|||||||
// Kanitkorn Sujautra <https://github.com/lukyth>
|
// Kanitkorn Sujautra <https://github.com/lukyth>
|
||||||
// Sebastian Silbermann <https://github.com/eps1lon>
|
// Sebastian Silbermann <https://github.com/eps1lon>
|
||||||
|
|
||||||
|
import { VNode } from '@vue/runtime-core'
|
||||||
import * as CSS from 'csstype'
|
import * as CSS from 'csstype'
|
||||||
|
|
||||||
export interface CSSProperties extends CSS.Properties<string | number> {
|
export interface CSSProperties extends CSS.Properties<string | number> {
|
||||||
@ -1338,7 +1339,7 @@ type NativeElements = {
|
|||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
namespace JSX {
|
namespace JSX {
|
||||||
interface Element {}
|
interface Element extends VNode {}
|
||||||
interface ElementClass {
|
interface ElementClass {
|
||||||
$props: {}
|
$props: {}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
import {
|
import {
|
||||||
|
h,
|
||||||
|
Text,
|
||||||
FunctionalComponent,
|
FunctionalComponent,
|
||||||
expectError,
|
expectError,
|
||||||
expectType,
|
expectType,
|
||||||
@ -6,7 +8,7 @@ import {
|
|||||||
} from './index'
|
} from './index'
|
||||||
|
|
||||||
// simple function signature
|
// simple function signature
|
||||||
const Foo = (props: { foo: number }) => props.foo
|
const Foo = (props: { foo: number }) => h(Text, null, props.foo)
|
||||||
|
|
||||||
// TSX
|
// TSX
|
||||||
expectType<JSX.Element>(<Foo foo={1} />)
|
expectType<JSX.Element>(<Foo foo={1} />)
|
||||||
|
@ -5,9 +5,11 @@ import {
|
|||||||
Fragment,
|
Fragment,
|
||||||
Teleport,
|
Teleport,
|
||||||
expectError,
|
expectError,
|
||||||
expectType
|
expectType,
|
||||||
|
VNode
|
||||||
} from './index'
|
} from './index'
|
||||||
|
|
||||||
|
expectType<VNode>(<div />)
|
||||||
expectType<JSX.Element>(<div />)
|
expectType<JSX.Element>(<div />)
|
||||||
expectType<JSX.Element>(<div id="foo" />)
|
expectType<JSX.Element>(<div id="foo" />)
|
||||||
expectType<JSX.Element>(<input value="foo" />)
|
expectType<JSX.Element>(<input value="foo" />)
|
||||||
|
Loading…
Reference in New Issue
Block a user