I have a select component and what I am trying to do is to implement the component in that way so I can pass an array of any type. How can this be done? Where should the generic be defined? I am using <script setup> with typescript.
This is how I tried to define the props:
const props = defineProps<T[]>({
options: {type: Array as PropType<T[]>, required: true }
})
Since you're using TypeScript, Vue allows you to do this:
const props = defineProps<{
options: T[];
}>();
https://vuejs.org/api/sfc-script-setup.html#typescript-only-features
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With