mirror of https://github.com/vuejs/core.git
fix(types): strip non-prop default values from return type of withDefaults (#9998)
close #9899
This commit is contained in:
parent
bb6babca8f
commit
44973bb3e7
|
@ -227,6 +227,19 @@ describe('withDefaults w/ boolean type', () => {
|
||||||
expectType<boolean | undefined>(res2.bool)
|
expectType<boolean | undefined>(res2.bool)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe('withDefaults w/ defineProp type is different from the defaults type', () => {
|
||||||
|
const res1 = withDefaults(
|
||||||
|
defineProps<{
|
||||||
|
bool?: boolean
|
||||||
|
}>(),
|
||||||
|
{ bool: false, value: false },
|
||||||
|
)
|
||||||
|
expectType<boolean>(res1.bool)
|
||||||
|
|
||||||
|
// @ts-expect-error
|
||||||
|
res1.value
|
||||||
|
})
|
||||||
|
|
||||||
describe('defineProps w/ runtime declaration', () => {
|
describe('defineProps w/ runtime declaration', () => {
|
||||||
// runtime declaration
|
// runtime declaration
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
|
|
|
@ -328,7 +328,9 @@ type PropsWithDefaults<
|
||||||
Defaults extends InferDefaults<T>,
|
Defaults extends InferDefaults<T>,
|
||||||
BKeys extends keyof T,
|
BKeys extends keyof T,
|
||||||
> = Readonly<MappedOmit<T, keyof Defaults>> & {
|
> = Readonly<MappedOmit<T, keyof Defaults>> & {
|
||||||
readonly [K in keyof Defaults]-?: K extends keyof T
|
readonly [K in keyof Defaults as K extends keyof T
|
||||||
|
? K
|
||||||
|
: never]-?: K extends keyof T
|
||||||
? Defaults[K] extends undefined
|
? Defaults[K] extends undefined
|
||||||
? IfAny<Defaults[K], NotUndefined<T[K]>, T[K]>
|
? IfAny<Defaults[K], NotUndefined<T[K]>, T[K]>
|
||||||
: NotUndefined<T[K]>
|
: NotUndefined<T[K]>
|
||||||
|
|
Loading…
Reference in New Issue