Skip to content
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
2 changes: 1 addition & 1 deletion src/mount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export type ComponentMountingOptions<
P extends ComponentProps<T> = ComponentProps<T>
> = Omit<MountingOptions<P, ComponentData<T>>, 'slots'> & {
slots?: {
[K in keyof ComponentSlots<T>]: WithArray<
[K in keyof ComponentSlots<T>]?: WithArray<
| ShimSlotReturnType<ComponentSlots<T>[K]>
| string
| VNode
Expand Down
83 changes: 82 additions & 1 deletion test-dts/mount.d-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import {
ref,
SetupContext,
Prop,
VNodeChild
VNodeChild,
SlotsType,
VNode
} from 'vue'
import { Options, Vue } from 'vue-class-component'
import { mount } from '../src'
Expand Down Expand Up @@ -340,3 +342,82 @@ expectError(
}
)
)

// slots
const SetupComponentWithSlots = defineComponent<
{
hello: string
},
{
hallo: () => void
},
string,
SlotsType<{
foo: () => VNode[]
bar: () => VNode[]
baz: () => VNode[]
}>
>((): any => {})

// optional slots
mount(SetupComponentWithSlots, {})

mount(SetupComponentWithSlots, {
slots: {}
})

mount(SetupComponentWithSlots, {
slots: {
foo: 'foo'
}
})

mount(SetupComponentWithSlots, {
slots: {
foo: 'foo',
bar: 'bar'
}
})

mount(SetupComponentWithSlots, {
slots: {
foo: 'foo',
bar: 'bar',
baz: 'baz'
}
})

// extra slots
mount(SetupComponentWithSlots, {
slots: {
// @ts-expect-error - This slot doesn't exist in the component and it should be reported.
extraSlot: 'nonExistentSlot'
}
})

mount(SetupComponentWithSlots, {
slots: {
foo: 'foo',
// @ts-expect-error - This slot doesn't exist in the component and it should be reported.
extraSlot: 'nonExistentSlot'
}
})

mount(SetupComponentWithSlots, {
slots: {
foo: 'foo',
bar: 'bar',
// @ts-expect-error - This slot doesn't exist in the component and it should be reported.
extraSlot: 'nonExistentSlot'
}
})

mount(SetupComponentWithSlots, {
slots: {
foo: 'foo',
bar: 'bar',
baz: 'baz',
// @ts-expect-error - This slot doesn't exist in the component and it should be reported.
extraSlot: 'nonExistentSlot'
}
})
1 change: 1 addition & 0 deletions test-dts/tsconfig.tsd.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"noEmit": false,
"skipLibCheck": true,
"experimentalDecorators": true,
"noUncheckedIndexedAccess": true,
"strictNullChecks": false
},
"exclude": [
Expand Down