diff --git a/packages/dts-test/setupHelpers.test-d.ts b/packages/dts-test/setupHelpers.test-d.ts index c749e80a5c7..883ebe6b254 100644 --- a/packages/dts-test/setupHelpers.test-d.ts +++ b/packages/dts-test/setupHelpers.test-d.ts @@ -102,6 +102,41 @@ describe('defineProps w/ union type declaration + withDefaults', () => { ) }) +describe('defineProps w/ object union + withDefaults', () => { + const props = withDefaults( + defineProps< + { + foo: string + } & ( + | { + type: 'hello' + bar: string + } + | { + type: 'world' + bar: number + } + ) + >(), + { + foo: 'default value!', + }, + ) + + expectType< + | { + readonly type: 'hello' + readonly bar: string + readonly foo: string + } + | { + readonly type: 'world' + readonly bar: number + readonly foo: string + } + >(props) +}) + describe('defineProps w/ generic type declaration + withDefaults', = T extends undefined ? never : T +type MappedOmit = { + [P in keyof T as P extends K ? never : P]: T[P] +} type InferDefaults = { [K in keyof T]?: InferDefault @@ -299,7 +302,7 @@ type PropsWithDefaults< T, Defaults extends InferDefaults, BKeys extends keyof T, -> = Readonly> & { +> = Readonly> & { readonly [K in keyof Defaults]-?: K extends keyof T ? Defaults[K] extends undefined ? T[K]