Skip to content

Commit da01118

Browse files
committed
fix(withDefaults/types): ensure default values of type any do not include undefined
1 parent 2a29a71 commit da01118

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

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

+5-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ describe('defineProps w/ generics', () => {
4242
test()
4343
})
4444

45-
describe('defineProps w/ type declaration + withDefaults', () => {
45+
describe('defineProps w/ type declaration + withDefaults', <T extends
46+
string>() => {
4647
const res = withDefaults(
4748
defineProps<{
4849
number?: number
@@ -55,6 +56,7 @@ describe('defineProps w/ type declaration + withDefaults', () => {
5556
z?: string
5657
bool?: boolean
5758
boolAndUndefined: boolean | undefined
59+
foo?: T
5860
}>(),
5961
{
6062
number: 123,
@@ -64,6 +66,7 @@ describe('defineProps w/ type declaration + withDefaults', () => {
6466
genStr: () => '',
6567
y: undefined,
6668
z: 'string',
69+
foo: '' as any,
6770
},
6871
)
6972

@@ -80,6 +83,7 @@ describe('defineProps w/ type declaration + withDefaults', () => {
8083
expectType<string | undefined>(res.x)
8184
expectType<string | undefined>(res.y)
8285
expectType<string>(res.z)
86+
expectType<T>(res.foo)
8387

8488
expectType<boolean>(res.bool)
8589
expectType<boolean>(res.boolAndUndefined)

packages/runtime-core/src/apiSetupHelpers.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {
2+
type IfAny,
23
type LooseRequired,
34
type Prettify,
45
type UnionToIntersection,
@@ -305,7 +306,7 @@ type PropsWithDefaults<
305306
> = Readonly<MappedOmit<T, keyof Defaults>> & {
306307
readonly [K in keyof Defaults]-?: K extends keyof T
307308
? Defaults[K] extends undefined
308-
? T[K]
309+
? IfAny<Defaults[K], NotUndefined<T[K]>, T[K]>
309310
: NotUndefined<T[K]>
310311
: never
311312
} & {

0 commit comments

Comments
 (0)