
TypeScript with Vue
Vue 3 TypeScript support, defineComponent, PropType, type inference, generic components, strict mode
1What is the primary role of defineComponent in Vue 3 with TypeScript?
What is the primary role of defineComponent in Vue 3 with TypeScript?
Answer
defineComponent enables TypeScript type inference for component options. Without this function, the this context would be treated as any in the Options API. It ensures that props, data, computed and methods are correctly typed automatically.
2Why use PropType when declaring complex props with runtime declaration?
Why use PropType when declaring complex props with runtime declaration?
Answer
PropType is a Vue utility type that allows casting prop types during runtime declaration. Object as PropType Book ensures that book is correctly typed as Book instead of a generic Object. This improves autocompletion and type safety without requiring script setup with generic types.
3What is the difference between script setup and script setup with lang='ts' for type inference?
What is the difference between script setup and script setup with lang='ts' for type inference?
Answer
script setup with lang='ts' enables TypeScript and allows automatic type inference without defineComponent. Props defined with defineProps are automatically typed, refs have full inference, and TypeScript errors are detected at compile time. Without lang='ts', no type checking is performed.
How to correctly type a ref that can be initially null in TypeScript?
What is the main advantage of generic components with script setup generic in Vue 3.3+?
+19 interview questions
Other Vue.js / Nuxt.js interview topics
JavaScript Fundamentals
Modern JavaScript (ES6+)
Vue Basics
Vue Components
Vue Router
Pinia State Management
Vuex (Legacy)
Composition API
Vue Reactivity
Nuxt Fundamentals
Nuxt Data Fetching
Nuxt SSR & SSG
Nuxt Server Routes
Nuxt Modules
Vue Composables
Vue Forms & Validation
Nuxt State Management
Vue Testing
Nuxt Deployment & CI/CD
Vue Performance
Vue Advanced Patterns
Nuxt Authentication
SEO with Nuxt
Nuxt Internationalization
Vue Architecture
Nuxt Security
Vue Ecosystem
Migration Vue 2→3 & Nuxt 2→3
Master Vue.js / Nuxt.js for your next interview
Access all questions, flashcards, technical tests, code review exercises and interview simulators.
Start for free