-
-
Notifications
You must be signed in to change notification settings - Fork 8.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(runtime-core): incomplete type inferred by generic components #9652
base: main
Are you sure you want to change the base?
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
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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)