mirror of https://github.com/vuejs/core.git
fix(types): correct withDefaults return type for boolean prop with undefined default value (#8602)
This commit is contained in:
parent
6a22b1f6c2
commit
f07cb18fed
|
@ -134,6 +134,26 @@ describe('defineProps w/ generic type declaration + withDefaults', <T extends nu
|
||||||
expectType<boolean>(res.bool)
|
expectType<boolean>(res.bool)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe('withDefaults w/ boolean type', () => {
|
||||||
|
const res1 = withDefaults(
|
||||||
|
defineProps<{
|
||||||
|
bool?: boolean
|
||||||
|
}>(),
|
||||||
|
{ bool: false }
|
||||||
|
)
|
||||||
|
expectType<boolean>(res1.bool)
|
||||||
|
|
||||||
|
const res2 = withDefaults(
|
||||||
|
defineProps<{
|
||||||
|
bool?: boolean
|
||||||
|
}>(),
|
||||||
|
{
|
||||||
|
bool: undefined
|
||||||
|
}
|
||||||
|
)
|
||||||
|
expectType<boolean | undefined>(res2.bool)
|
||||||
|
})
|
||||||
|
|
||||||
describe('defineProps w/ runtime declaration', () => {
|
describe('defineProps w/ runtime declaration', () => {
|
||||||
// runtime declaration
|
// runtime declaration
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
|
|
|
@ -303,7 +303,13 @@ type PropsWithDefaults<
|
||||||
? T[K]
|
? T[K]
|
||||||
: NotUndefined<T[K]>
|
: NotUndefined<T[K]>
|
||||||
: never
|
: never
|
||||||
} & { readonly [K in BKeys]-?: boolean }
|
} & {
|
||||||
|
readonly [K in BKeys]-?: K extends keyof Defaults
|
||||||
|
? Defaults[K] extends undefined
|
||||||
|
? boolean | undefined
|
||||||
|
: boolean
|
||||||
|
: boolean
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Vue `<script setup>` compiler macro for providing props default values when
|
* Vue `<script setup>` compiler macro for providing props default values when
|
||||||
|
|
Loading…
Reference in New Issue