Skip to content

Commit cab769f

Browse files
authoredJun 12, 2020
fix(types): add RawSlots in h signature (#1293)
1 parent b015892 commit cab769f

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed
 

‎packages/runtime-core/__tests__/h.spec.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { h } from '../src/h'
22
import { createVNode } from '../src/vnode'
3+
import { RawSlots } from '../src/componentSlots'
34

45
// Since h is a thin layer on top of createVNode, we are only testing its
56
// own logic here. Details of vnode creation is tested in vnode.spec.ts.
@@ -31,8 +32,14 @@ describe('renderer: h', () => {
3132
test('type + props + children', () => {
3233
// array
3334
expect(h('div', {}, ['foo'])).toMatchObject(createVNode('div', {}, ['foo']))
34-
// default slot
35+
// slots
36+
const slots = {} as RawSlots
37+
expect(h('div', {}, slots)).toMatchObject(createVNode('div', {}, slots))
3538
const Component = { template: '<br />' }
39+
expect(h(Component, {}, slots)).toMatchObject(
40+
createVNode(Component, {}, slots)
41+
)
42+
// default slot
3643
const slot = () => {}
3744
expect(h(Component, {}, slot)).toMatchObject(
3845
createVNode(Component, {}, slot)

‎packages/runtime-core/src/h.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export function h(type: string, children?: RawChildren): VNode
8080
export function h(
8181
type: string,
8282
props?: RawProps | null,
83-
children?: RawChildren
83+
children?: RawChildren | RawSlots
8484
): VNode
8585

8686
// fragment

‎test-dts/h.test-d.ts

+3
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ describe('h inference w/ element', () => {
2929
expectError(h('div', { ref: {} }))
3030
// @ts-expect-error
3131
expectError(h('div', { ref: 123 }))
32+
// slots
33+
const slots = { default: () => {} } // RawSlots
34+
h('div', {}, slots)
3235
})
3336

3437
describe('h inference w/ Fragment', () => {

0 commit comments

Comments
 (0)
Please sign in to comment.