How to set prop with generic type array?

Viewed 291

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 }
})
2 Answers

you can use like this

const props = defineProps<{
  options: string[],
}>();
Related