Skip to content

Commit

Permalink
test(runtime-core): incomplete type inferred by generic components
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
pfumagalli committed Nov 28, 2023
1 parent e1aacb0 commit 3c17382
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions packages/dts-test/setupHelpers.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
useAttrs,
useSlots,
withDefaults,
PropType,
Slots,
defineSlots,
VNode,
Expand Down Expand Up @@ -193,6 +194,26 @@ describe('defineProps w/ runtime declaration', () => {
props2.baz
})

describe('defineProps w/ generics and runtime declarations', () => {
function test<T extends Record<string, any>>() {
const props = defineProps({
foo: {
type: Object as PropType<T>,
required: false,
default: null,
},
bar: {
type: Object as PropType<T>,
required: true,
},
})
expectType<T | null>(props.foo)
expectType<T>(props.bar)
}
test()
})


describe('defineEmits w/ type declaration', () => {
const emit = defineEmits<(e: 'change') => void>()
emit('change')
Expand Down

0 comments on commit 3c17382

Please sign in to comment.