Skip to content

Commit dbb0a3a

Browse files
committed
fix(types): add RawSlots in h signature
`RawSlots` is supported as a third argument in most signatures except when the first one is a `string`. I _think_ this is a valid use-case, as @dobromir-hristov used it for stubs in VTU next. We are currently forced to cast the parameter as `any` to make TS happy in VTU. This commit should fix that.
1 parent 4faa289 commit dbb0a3a

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
@@ -23,6 +23,9 @@ describe('h inference w/ element', () => {
2323
expectError(h('div', { ref: [] }))
2424
expectError(h('div', { ref: {} }))
2525
expectError(h('div', { ref: 123 }))
26+
// slots
27+
const slots = { default: () => {} } // RawSlots
28+
h('div', {}, slots)
2629
})
2730

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

0 commit comments

Comments
 (0)