0Pricing
Vue Academy · Lesson

Generic Vue Components

defineComponent with generics, generic script setup, typed slot props.

Generic Components

Some components work with any data type — a typed list, a select, a table. Vue 3.3 lets you write generic components so the consumer keeps full type inference instead of falling back to any.

The generic Attribute

Add a generic attribute to <script setup>. It declares type parameters available throughout the script, exactly like a generic function.

<script setup lang="ts" generic="T">
// T can now be used below
</script>

All lessons in this course

  1. TypeScript Setup in Vue Projects
  2. Typed Props and Emits with defineProps/defineEmits
  3. Typing Composables and Refs
  4. Generic Vue Components
← Back to Vue Academy