0
0
Vueframework~10 mins

Why TypeScript matters in Vue - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to define a reactive variable with TypeScript in Vue.

Vue
const count = ref[1](0);
Drag options to blanks, or click blank then click option'
A[number]
B(number)
C<number>
D{number}
Attempts:
3 left
💡 Hint
Common Mistakes
Using parentheses instead of angle brackets for type.
Using square brackets or curly braces which are not valid here.
2fill in blank
medium

Complete the code to define a prop with a specific type in a Vue component using TypeScript.

Vue
defineProps<{ title: [1] }>();
Drag options to blanks, or click blank then click option'
Astring
BString
Cstr
Dtext
Attempts:
3 left
💡 Hint
Common Mistakes
Using String (capitalized) which is a JavaScript constructor, not a TypeScript type.
Using made-up types like str or text.
3fill in blank
hard

Fix the error in the Vue component's setup function by completing the return type annotation.

Vue
setup(): [1] { return { count }; }
Drag options to blanks, or click blank then click option'
Avoid
BRecord<string, any>
Cnumber
Dobject
Attempts:
3 left
💡 Hint
Common Mistakes
Using void which means no return value.
Using number which is a primitive, not an object.
Using object which is less specific and can cause issues.
4fill in blank
hard

Fill both blanks to define a reactive object with typed properties in Vue using TypeScript.

Vue
const user = reactive<{ name: [1]; age: [2] }>({ name: '', age: 0 });
Drag options to blanks, or click blank then click option'
Astring
Bnumber
Cboolean
Dany
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up types like using boolean for text or numbers.
Using any which loses type safety.
5fill in blank
hard

Fill all three blanks to create a computed property with a typed getter in Vue using TypeScript.

Vue
const doubleCount = computed<[1]>(() => count.value [2] 2 [3] 0);
Drag options to blanks, or click blank then click option'
Anumber
B*
C+
D-
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong types like string for numeric results.
Using wrong operators that cause syntax errors.