Skip to content

Commit 3c17382

Browse files
committed
test(runtime-core): incomplete type inferred by generic components
Added test to ensure that `script setup` with a generic argument _and_ runtime declarations returns the correct type, and verified that the test does _not_ pass without the patch.
1 parent e1aacb0 commit 3c17382

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
useAttrs,
55
useSlots,
66
withDefaults,
7+
PropType,
78
Slots,
89
defineSlots,
910
VNode,
@@ -193,6 +194,26 @@ describe('defineProps w/ runtime declaration', () => {
193194
props2.baz
194195
})
195196

197+
describe('defineProps w/ generics and runtime declarations', () => {
198+
function test<T extends Record<string, any>>() {
199+
const props = defineProps({
200+
foo: {
201+
type: Object as PropType<T>,
202+
required: false,
203+
default: null,
204+
},
205+
bar: {
206+
type: Object as PropType<T>,
207+
required: true,
208+
},
209+
})
210+
expectType<T | null>(props.foo)
211+
expectType<T>(props.bar)
212+
}
213+
test()
214+
})
215+
216+
196217
describe('defineEmits w/ type declaration', () => {
197218
const emit = defineEmits<(e: 'change') => void>()
198219
emit('change')

0 commit comments

Comments
 (0)