diff --git a/packages/dts-test/defineComponent.test-d.tsx b/packages/dts-test/defineComponent.test-d.tsx index add9c8a3fc0..32912dd9a2a 100644 --- a/packages/dts-test/defineComponent.test-d.tsx +++ b/packages/dts-test/defineComponent.test-d.tsx @@ -1414,6 +1414,8 @@ describe('slots', () => { slots: Object as SlotsType<{ default: { foo: string; bar: number } optional?: { data: string } + undefinedScope: undefined | { data: string } + optionalUndefinedScope?: undefined | { data: string } }>, setup(props, { slots }) { expectType<(scope: { foo: string; bar: number }) => VNode[]>( @@ -1429,6 +1431,33 @@ describe('slots', () => { slots.optional({ data: 'foo' }) slots.optional?.({ data: 'foo' }) + expectType<{ + (): VNode[] + (scope: undefined | { data: string }): VNode[] + }>(slots.undefinedScope) + + expectType< + | { (): VNode[]; (scope: undefined | { data: string }): VNode[] } + | undefined + >(slots.optionalUndefinedScope) + + slots.default({ foo: 'foo', bar: 1 }) + // @ts-expect-error it's optional + slots.optional({ data: 'foo' }) + slots.optional?.({ data: 'foo' }) + slots.undefinedScope() + slots.undefinedScope(undefined) + // @ts-expect-error + slots.undefinedScope('foo') + + slots.optionalUndefinedScope?.() + slots.optionalUndefinedScope?.(undefined) + slots.optionalUndefinedScope?.({ data: 'foo' }) + // @ts-expect-error + slots.optionalUndefinedScope() + // @ts-expect-error + slots.optionalUndefinedScope?.('foo') + expectType(new comp1().$slots) } }) diff --git a/packages/runtime-core/src/componentSlots.ts b/packages/runtime-core/src/componentSlots.ts index 1a0db39cadb..e48fae98ee7 100644 --- a/packages/runtime-core/src/componentSlots.ts +++ b/packages/runtime-core/src/componentSlots.ts @@ -25,7 +25,7 @@ import { DeprecationTypes, isCompatEnabled } from './compat/compatConfig' import { toRaw } from '@vue/reactivity' export type Slot = ( - ...args: IfAny + ...args: IfAny ) => VNode[] export type InternalSlots = { @@ -44,7 +44,7 @@ export type TypedSlots = [keyof S] extends [never] : Readonly< Prettify<{ [K in keyof NonNullable]: Slot< - NonNullable[K]> + NonNullable[K] > }> >