fix(runtime-core): incomplete type inferred by generic components#9652
fix(runtime-core): incomplete type inferred by generic components#9652pfumagalli wants to merge 1 commit intovuejs:mainfrom
Conversation
|
@pfumagalli can you a test? |
|
@pikax ... add? run? a test... Sure, can you point me to an example on how types are tested here? Will be happy to comply once I see how those are dealt with! |
|
@pfumagalli, sorry :D Yes, add a test, probably in here: https://github.com/vuejs/core/blob/main/packages/dts-test/setupHelpers.test-d.ts |
|
@pikax Fabulous, TSD, love it... Give me a few hours to finish daytime work, and I'll get right on it! |
|
@pikax test added, and verified that it does NOT pass without the supplied patch. Thank you for pointing me in the right direction! |
|
Hold on... This breaks some other DTS tests... Checking. |
|
Consolidated fixes into a single commit (easier on the eyes). |
|
@pikax this should be ready to go now! |
Size ReportBundles
Usages
|
pikax
left a comment
There was a problem hiding this comment.
This only seems to work with full prop declaration, it does not seem to work with:
describe('defineProps w/ generics and runtime declarations', <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
},
baz: Object as PropType<T>
})
expectType<T | null>(props.foo)
expectType<T>(props.bar)
expectType<T | undefined>(props.baz)
// @ts-expect-error should not be a string
expectType<string>(props.foo)
// @ts-expect-error should not be a string
expectType<string>(props.bar)
// @ts-expect-error should not be a string
expectType<string>(props.baz)
})
close #9610
This fixes the wrong type inferred by
defineProps(...)using generic components as outlined in #9610 (and related #9546, #9277)