diff --git a/src/mount.ts b/src/mount.ts index 1adc7588e..0046c461e 100644 --- a/src/mount.ts +++ b/src/mount.ts @@ -24,7 +24,7 @@ export type ComponentMountingOptions< P extends ComponentProps = ComponentProps > = Omit>, 'slots'> & { slots?: { - [K in keyof ComponentSlots]: WithArray< + [K in keyof ComponentSlots]?: WithArray< | ShimSlotReturnType[K]> | string | VNode diff --git a/test-dts/mount.d-test.ts b/test-dts/mount.d-test.ts index feadf91f4..7996fd56a 100644 --- a/test-dts/mount.d-test.ts +++ b/test-dts/mount.d-test.ts @@ -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' @@ -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' + } +}) diff --git a/test-dts/tsconfig.tsd.json b/test-dts/tsconfig.tsd.json index f10ca8eb3..536ae6ded 100644 --- a/test-dts/tsconfig.tsd.json +++ b/test-dts/tsconfig.tsd.json @@ -4,6 +4,7 @@ "noEmit": false, "skipLibCheck": true, "experimentalDecorators": true, + "noUncheckedIndexedAccess": true, "strictNullChecks": false }, "exclude": [