Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(jsx): JSX.Element extends VNode #3171

Merged
merged 4 commits into from
Mar 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions packages/runtime-core/src/h.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import {
createVNode,
VNodeArrayChildren,
Fragment,
Text,
Comment,
isVNode
} from './vnode'
import { Teleport, TeleportProps } from './components/Teleport'
Expand Down Expand Up @@ -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(
Expand Down
3 changes: 2 additions & 1 deletion packages/runtime-dom/types/jsx.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down Expand Up @@ -1338,7 +1339,7 @@ type NativeElements = {

declare global {
namespace JSX {
interface Element {}
interface Element extends VNode {}
interface ElementClass {
$props: {}
}
Expand Down
4 changes: 3 additions & 1 deletion test-dts/functionalComponent.test-d.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import {
h,
Text,
FunctionalComponent,
expectError,
expectType,
Component
} 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} />)
Expand Down
4 changes: 3 additions & 1 deletion test-dts/tsx.test-d.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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" />)
Expand Down