diff --git a/types/test/setup-helpers-test.ts b/types/test/setup-helpers-test.ts index 744c2a533..4876154b6 100644 --- a/types/test/setup-helpers-test.ts +++ b/types/test/setup-helpers-test.ts @@ -19,15 +19,19 @@ describe('defineProps w/ type declaration + withDefaults', () => { arr?: string[] obj?: { x: number } fn?: (e: string) => void - x?: string genStr?: string + x?: string + y?: string + z?: string }>(), { number: 123, arr: () => [], obj: () => ({ x: 123 }), fn: () => {}, - genStr: () => '' + genStr: () => '', + y: undefined, + z: 'string' } ) @@ -35,9 +39,15 @@ describe('defineProps w/ type declaration + withDefaults', () => { res.arr.push('hi') res.obj.x res.fn('hi') + res.genStr.slice() // @ts-expect-error res.x.slice() - res.genStr.slice() + // @ts-expect-error + res.y.slice() + + expectType(res.x) + expectType(res.y) + expectType(res.z) }) describe('defineProps w/ union type declaration + withDefaults', () => { diff --git a/types/v3-setup-helpers.d.ts b/types/v3-setup-helpers.d.ts index 6a62fd16f..165605ee5 100644 --- a/types/v3-setup-helpers.d.ts +++ b/types/v3-setup-helpers.d.ts @@ -110,7 +110,11 @@ type InferDefault = T extends : (props: P) => T type PropsWithDefaults = Base & { - [K in keyof Defaults]: K extends keyof Base ? NotUndefined : never + [K in keyof Defaults]: K extends keyof Base + ? Defaults[K] extends undefined + ? Base[K] + : NotUndefined + : never } /**