Skip to content

Commit 44973bb

Browse files
fix(types): strip non-prop default values from return type of withDefaults (#9998)
close #9899
1 parent bb6babc commit 44973bb

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

packages-private/dts-test/setupHelpers.test-d.ts

+13
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,19 @@ describe('withDefaults w/ boolean type', () => {
227227
expectType<boolean | undefined>(res2.bool)
228228
})
229229

230+
describe('withDefaults w/ defineProp type is different from the defaults type', () => {
231+
const res1 = withDefaults(
232+
defineProps<{
233+
bool?: boolean
234+
}>(),
235+
{ bool: false, value: false },
236+
)
237+
expectType<boolean>(res1.bool)
238+
239+
// @ts-expect-error
240+
res1.value
241+
})
242+
230243
describe('defineProps w/ runtime declaration', () => {
231244
// runtime declaration
232245
const props = defineProps({

packages/runtime-core/src/apiSetupHelpers.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,9 @@ type PropsWithDefaults<
328328
Defaults extends InferDefaults<T>,
329329
BKeys extends keyof T,
330330
> = Readonly<MappedOmit<T, keyof Defaults>> & {
331-
readonly [K in keyof Defaults]-?: K extends keyof T
331+
readonly [K in keyof Defaults as K extends keyof T
332+
? K
333+
: never]-?: K extends keyof T
332334
? Defaults[K] extends undefined
333335
? IfAny<Defaults[K], NotUndefined<T[K]>, T[K]>
334336
: NotUndefined<T[K]>

0 commit comments

Comments
 (0)