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', () => {
// runtime declaration
const props = defineProps({
? T[K]
: NotUndefined<T[K]>
: 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