Skip to content

Commit

Permalink
fix(types): add RawSlots in h signature
Browse files Browse the repository at this point in the history
`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.
  • Loading branch information
cexbrayat committed Jun 4, 2020
1 parent 4faa289 commit dbb0a3a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
9 changes: 8 additions & 1 deletion packages/runtime-core/__tests__/h.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { h } from '../src/h'
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
// own logic here. Details of vnode creation is tested in vnode.spec.ts.
Expand Down Expand Up @@ -31,8 +32,14 @@ describe('renderer: h', () => {
test('type + props + children', () => {
// array
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 />' }
expect(h(Component, {}, slots)).toMatchObject(
createVNode(Component, {}, slots)
)
// default slot
const slot = () => {}
expect(h(Component, {}, slot)).toMatchObject(
createVNode(Component, {}, slot)
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime-core/src/h.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export function h(type: string, children?: RawChildren): VNode
export function h(
type: string,
props?: RawProps | null,
children?: RawChildren
children?: RawChildren | RawSlots
): VNode

// fragment
Expand Down
3 changes: 3 additions & 0 deletions test-dts/h.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ describe('h inference w/ element', () => {
expectError(h('div', { ref: [] }))
expectError(h('div', { ref: {} }))
expectError(h('div', { ref: 123 }))
// slots
const slots = { default: () => {} } // RawSlots
h('div', {}, slots)
})

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

0 comments on commit dbb0a3a

Please sign in to comment.