Skip to content

Commit f07cb18

Browse files
authored
fix(types): correct withDefaults return type for boolean prop with undefined default value (#8602)
1 parent 6a22b1f commit f07cb18

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,26 @@ describe('defineProps w/ generic type declaration + withDefaults', <T extends nu
134134
expectType<boolean>(res.bool)
135135
})
136136

137+
describe('withDefaults w/ boolean type', () => {
138+
const res1 = withDefaults(
139+
defineProps<{
140+
bool?: boolean
141+
}>(),
142+
{ bool: false }
143+
)
144+
expectType<boolean>(res1.bool)
145+
146+
const res2 = withDefaults(
147+
defineProps<{
148+
bool?: boolean
149+
}>(),
150+
{
151+
bool: undefined
152+
}
153+
)
154+
expectType<boolean | undefined>(res2.bool)
155+
})
156+
137157
describe('defineProps w/ runtime declaration', () => {
138158
// runtime declaration
139159
const props = defineProps({

packages/runtime-core/src/apiSetupHelpers.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,13 @@ type PropsWithDefaults<
303303
? T[K]
304304
: NotUndefined<T[K]>
305305
: never
306-
} & { readonly [K in BKeys]-?: boolean }
306+
} & {
307+
readonly [K in BKeys]-?: K extends keyof Defaults
308+
? Defaults[K] extends undefined
309+
? boolean | undefined
310+
: boolean
311+
: boolean
312+
}
307313

308314
/**
309315
* Vue `<script setup>` compiler macro for providing props default values when

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy