I’ve got a generic component receiving
props: {
options: {
type: Array as PropType<unknown[]>,
default: () => []
},
labelKey: {
type: String,
default: "label"
}
}
and, somewhere in the template I use
<SomeComponent
v-for="(item) in options"
v-text="item[labelKey]"
...
/>
Ideally I’d like to be able to pass the type of an option item (e.g: T
) to the component and also let TS know labelKey
is keyof T
. Is this even possible with Vue?
Now my only option is to expect the error:
<SomeComponent
v-for="(item) in options"
/* @ts-expect-error: for TS item is unknown */
v-text="item[labelKey]"
...
/>