0Pricing
Vue Academy · Lesson

Typed Props and Emits with defineProps/defineEmits

Generic defineProps (), complex types, optional props, emit typing.

Typing Component Inputs and Outputs

With lang="ts", the defineProps and defineEmits macros accept TypeScript types directly. This gives compile-time checks on what data flows in and out of a component.

Props From an Interface

Pass a type to the defineProps generic. An interface keeps complex prop shapes readable and reusable.

<script setup lang="ts">
interface Props {
  title: string
  count: number
}
const props = defineProps<Props>()
</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