Consider this Vue 3 component using <script setup> and typed props. What will it render when used as <Greeting name="Alice" age=30 />?
<script setup lang="ts"> import { defineProps } from 'vue' const props = defineProps<{ name: string; age: number }>() </script> <template> <p>Hello, {{ props.name }}! You are {{ props.age }} years old.</p> </template>
Remember that defineProps creates a typed props object you can use directly in the template.
The component uses defineProps with a typed object. The template accesses props.name and props.age, so the values passed in render correctly.
Given a prop count that should be a number with a default of 10, which option correctly types and sets the default in a Vue 3 <script setup lang="ts"> component?
Optional props need ? in the type and a fallback value in code.
Option B correctly marks count as optional and uses nullish coalescing to provide a default value. Option B lacks TypeScript typing. Option B requires count to be always present. Option B uses || which can wrongly override valid zero values.
Examine this Vue 3 component snippet. Why does TypeScript report an error on props.title.toUpperCase()?
<script setup lang="ts"> const props = defineProps<{ title?: string }>() const upperTitle = props.title.toUpperCase() </script>
Think about what happens if title is missing.
Since title is optional, it can be undefined. Calling toUpperCase() on undefined causes an error. You must check or provide a default before calling string methods.
count after this Vue component runs?Given this Vue 3 component using typed props and a reactive state, what is the final value of count after mounting?
<script setup lang="ts"> import { ref, watch } from 'vue' const props = defineProps<{ initialCount: number }>() const count = ref(props.initialCount) watch(() => props.initialCount, (newVal) => { count.value = newVal * 2 }, { immediate: true }) </script> <!-- Used as: <Counter initialCount=5 /> -->
Consider how the watcher updates count when initialCount changes.
The count ref starts at 5 from props. The watcher triggers immediately on mount because initialCount is 5, updating count to 10 (5 * 2).
Choose the correct statement about typing props in Vue 3 with TypeScript and <script setup>.
Think about the difference between TypeScript checks and Vue runtime behavior.
TypeScript typing with defineProps<T>() only checks types during development (compile time). Vue does not enforce these types at runtime unless you define prop options with type and validator.