Complete the code to define a typed ref in Vue Composition API.
import { ref } from 'vue'; const count = ref<[1]>(0);
The ref is typed with number because the initial value is 0, a number.
Complete the code to type a reactive object with Vue's Composition API.
import { reactive } from 'vue'; interface User { name: string; age: number; } const user = reactive<[1]>({ name: 'Alice', age: 30 });
The reactive object is typed with the User interface to ensure correct property types.
Fix the error in typing a computed property in Vue Composition API.
import { computed } from 'vue'; const doubleCount = computed<[1]>(() => count.value * 2);
The computed property returns a number because it doubles a numeric count.
Fill both blanks to type a composable function that returns a typed ref and a typed function.
import { ref } from 'vue'; function useCounter() { const count = ref<[1]>(0); function increment(): [2] { count.value++; } return { count, increment }; }
The count ref is a number, and increment returns nothing, so its return type is void.
Fill all three blanks to type a composable that returns a reactive object, a computed property, and a method with correct types.
import { reactive, computed } from 'vue'; interface Todo { text: string; done: boolean; } function useTodo() { const state = reactive<[1]>({ text: '', done: false }); const status = computed<[2]>(() => (state.done ? 'Done' : 'Pending')); function toggle(): [3] { state.done = !state.done; } return { state, status, toggle }; }
The reactive object is typed as Todo. The computed property returns a string. The toggle method returns void because it does not return a value.