Closed as duplicate of#12637
Description
Vue version
3.5.13
Link to minimal reproduction
Steps to reproduce
Open the reproduction and have a look at the type error on the <OptionalGenericExample />
component in the template.
I defined an optional prop:
interface Props<T> {
val?: T
}
and used it in a generic component:
const OptionalGenericExample = defineComponent(
<T extends string>(props: Props<T>) => {
return () => h('div', [
'OptionalExample'
])
},
{
props: ['val']
}
)
When used in the template without providing the prop, the following error is shown:
Argument of type '{}' is not assignable to parameter of type '{ val: any; } & VNodeProps & AllowedComponentProps & ComponentCustomProps & Record<string, unknown>'.
Property 'val' is missing in type '{}' but required in type '{ val: any; }'.
<template>
<OptionalGenericExample />
</template>
This doesn't happen when the component is not generic.
What is expected?
I would expect no error to be present, since the prop is optional and doesn't need to be specified.
What is actually happening?
A type error is present.
System Info
Any additional comments?
No response
Metadata
Metadata
Assignees
Labels
No labels