Vue.js / Nuxt.js

TypeScript with Vue

Vue 3 TypeScript support, defineComponent, PropType, type inference, generic components, strict mode

22 คำถามสัมภาษณ์·
Senior
1

What is the primary role of defineComponent in Vue 3 with TypeScript?

คำตอบ

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.

2

Why use PropType when declaring complex props with runtime declaration?

คำตอบ

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.

3

What is the difference between script setup and script setup with lang='ts' for type inference?

คำตอบ

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.

4

How to correctly type a ref that can be initially null in TypeScript?

5

What is the main advantage of generic components with script setup generic in Vue 3.3+?

+19 คำถามสัมภาษณ์

เชี่ยวชาญ Vue.js / Nuxt.js สำหรับการสัมภาษณ์ครั้งถัดไป

เข้าถึงคำถามทั้งหมด flashcards แบบทดสอบเทคนิค แบบฝึกหัด code review และตัวจำลองสัมภาษณ์

เริ่มใช้ฟรี