diff --git a/packages/dts-test/setupHelpers.test-d.ts b/packages/dts-test/setupHelpers.test-d.ts index 77342590dc6..934e6056d2d 100644 --- a/packages/dts-test/setupHelpers.test-d.ts +++ b/packages/dts-test/setupHelpers.test-d.ts @@ -134,6 +134,26 @@ describe('defineProps w/ generic type declaration + withDefaults', (res.bool) }) +describe('withDefaults w/ boolean type', () => { + const res1 = withDefaults( + defineProps<{ + bool?: boolean + }>(), + { bool: false } + ) + expectType(res1.bool) + + const res2 = withDefaults( + defineProps<{ + bool?: boolean + }>(), + { + bool: undefined + } + ) + expectType(res2.bool) +}) + describe('defineProps w/ runtime declaration', () => { // runtime declaration const props = defineProps({ diff --git a/packages/runtime-core/src/apiSetupHelpers.ts b/packages/runtime-core/src/apiSetupHelpers.ts index c00937981d9..93200667081 100644 --- a/packages/runtime-core/src/apiSetupHelpers.ts +++ b/packages/runtime-core/src/apiSetupHelpers.ts @@ -303,7 +303,13 @@ type PropsWithDefaults< ? T[K] : NotUndefined : never -} & { readonly [K in BKeys]-?: boolean } +} & { + readonly [K in BKeys]-?: K extends keyof Defaults + ? Defaults[K] extends undefined + ? boolean | undefined + : boolean + : boolean +} /** * Vue `