fix(types): add RawSlots in h signature (#1293)

This commit is contained in:
Cédric Exbrayat 2020-06-12 16:38:56 +02:00 committed by GitHub
parent b015892de6
commit cab769f174
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 2 deletions

View File

@ -1,5 +1,6 @@
import { h } from '../src/h' import { h } from '../src/h'
import { createVNode } from '../src/vnode' import { createVNode } from '../src/vnode'
import { RawSlots } from '../src/componentSlots'
// Since h is a thin layer on top of createVNode, we are only testing its // Since h is a thin layer on top of createVNode, we are only testing its
// own logic here. Details of vnode creation is tested in vnode.spec.ts. // own logic here. Details of vnode creation is tested in vnode.spec.ts.
@ -31,8 +32,14 @@ describe('renderer: h', () => {
test('type + props + children', () => { test('type + props + children', () => {
// array // array
expect(h('div', {}, ['foo'])).toMatchObject(createVNode('div', {}, ['foo'])) expect(h('div', {}, ['foo'])).toMatchObject(createVNode('div', {}, ['foo']))
// default slot // slots
const slots = {} as RawSlots
expect(h('div', {}, slots)).toMatchObject(createVNode('div', {}, slots))
const Component = { template: '<br />' } const Component = { template: '<br />' }
expect(h(Component, {}, slots)).toMatchObject(
createVNode(Component, {}, slots)
)
// default slot
const slot = () => {} const slot = () => {}
expect(h(Component, {}, slot)).toMatchObject( expect(h(Component, {}, slot)).toMatchObject(
createVNode(Component, {}, slot) createVNode(Component, {}, slot)

View File

@ -80,7 +80,7 @@ export function h(type: string, children?: RawChildren): VNode
export function h( export function h(
type: string, type: string,
props?: RawProps | null, props?: RawProps | null,
children?: RawChildren children?: RawChildren | RawSlots
): VNode ): VNode
// fragment // fragment

View File

@ -29,6 +29,9 @@ describe('h inference w/ element', () => {
expectError(h('div', { ref: {} })) expectError(h('div', { ref: {} }))
// @ts-expect-error // @ts-expect-error
expectError(h('div', { ref: 123 })) expectError(h('div', { ref: 123 }))
// slots
const slots = { default: () => {} } // RawSlots
h('div', {}, slots)
}) })
describe('h inference w/ Fragment', () => { describe('h inference w/ Fragment', () => {