Boolean Casting of shorthand prop not working if the prop's type is generic
Vue version
v3.2.41
Link to minimal reproduction
Steps to reproduce
Props are displayed in the preview. Please refer to the File ComponentWithGenericProps.vue
to see the definition
What is expected?
The shorthand prop is converted to boolean regardless of how it is defined
What is actually happening?
Given the following props definition, both the multiple
and explicitBoolean
properties are created on the props object. So far so good. However, if multiple
is passed as short-hand flag, it's value will be an empty string rather than true
.
interface Props<T = boolean> {
multiple: T
explicitBoolean?: boolean
modelValue: T extends true ? string[] : string|null
}
const props = defineProps<Props<boolean>>()
System Info
No response
Any additional comments?
No response
I guess there is no Generics support yet. https://github.com/vuejs/docs/blob/380d98b8f35cbfb8a2968ab7e51933fa52da8adc/src/api/sfc-script-setup.md?plain=1#L266
I did find a work-around to get the boolean casting to work by using an additional union type with boolean (multiple: T | boolean
). However, I have come to realise that TypeScript does not resolve the dependant property's type (modelValue
is always a union type, even in a literal object with multiple
set), so it really doesn't matter either way. Perhaps this use-case would work better if union types were supported on the top level for defineProps but that's probably asking too much.