# TypeScript กับ Vue (Vue.js / Nuxt.js) > การรองรับ TypeScript ใน Vue 3, defineComponent, PropType, type inference, generic components, strict mode - 22 คำถามสัมภาษณ์ - Senior - [คำถามสัมภาษณ์: Vue.js / Nuxt.js](https://sharpskill.dev/th/technologies/vue-nuxt/interview-questions.md) ## 1. บทบาทหลักของ defineComponent ใน Vue 3 ที่ใช้ TypeScript คืออะไร? **คำตอบ** defineComponent เปิดใช้งาน type inference ของ TypeScript สำหรับ options ของ component หากไม่มีฟังก์ชันนี้ บริบท this จะถูกมองเป็น any ใน Options API ซึ่งช่วยให้ props, data, computed และเมธอดถูกกำหนดชนิดอย่างถูกต้องโดยอัตโนมัติ ## 2. ทำไมจึงควรใช้ PropType เมื่อประกาศ props ที่ซับซ้อนด้วย runtime declaration? **คำตอบ** PropType เป็น utility type ของ Vue ที่ช่วยให้สามารถ cast ชนิดของ prop ระหว่างการประกาศแบบ runtime ได้ Object as PropType Book ทำให้มั่นใจว่า book ถูกกำหนดชนิดอย่างถูกต้องเป็น Book แทนที่จะเป็น Object ทั่วไป สิ่งนี้ช่วยปรับปรุงการเติมข้อความอัตโนมัติและความปลอดภัยของชนิดข้อมูลโดยไม่ต้องใช้ script setup ที่มี generic types ## 3. ความแตกต่างระหว่าง script setup กับ script setup ที่มี lang='ts' ในแง่ของ type inference คืออะไร? **คำตอบ** script setup ที่มี lang='ts' จะเปิดใช้งาน TypeScript และอนุญาตให้มี type inference อัตโนมัติโดยไม่ต้องใช้ defineComponent props ที่กำหนดด้วย defineProps จะถูกกำหนดชนิดโดยอัตโนมัติ refs มี inference ที่สมบูรณ์ และ error ของ TypeScript จะถูกตรวจพบในเวลาคอมไพล์ หากไม่มี lang='ts' จะไม่มีการตรวจสอบชนิดข้อมูลเลย ## มีอีก 19 คำถาม - จะกำหนดชนิดให้กับ ref ที่อาจเป็น null ในตอนแรกใน TypeScript อย่างถูกต้องได้อย่างไร? - ข้อได้เปรียบหลักของ generic component ที่ใช้ script setup generic ใน Vue 3.3+ คืออะไร? สมัครฟรี: https://sharpskill.dev/th/login ## หัวข้อสัมภาษณ์ Vue.js / Nuxt.js อื่นๆ - [พื้นฐาน JavaScript](https://sharpskill.dev/th/technologies/vue-nuxt/interview-questions/javascript-fundamentals.md): 20 คำถาม, Junior - [JavaScript สมัยใหม่ (ES6+)](https://sharpskill.dev/th/technologies/vue-nuxt/interview-questions/es6-modern-javascript.md): 20 คำถาม, Junior - [พื้นฐาน Vue](https://sharpskill.dev/th/technologies/vue-nuxt/interview-questions/vue-basics.md): 22 คำถาม, Junior - [คอมโพเนนต์ Vue](https://sharpskill.dev/th/technologies/vue-nuxt/interview-questions/vue-components.md): 20 คำถาม, Junior - [Vue Router](https://sharpskill.dev/th/technologies/vue-nuxt/interview-questions/vue-router.md): 18 คำถาม, Junior - [Pinia State Management](https://sharpskill.dev/th/technologies/vue-nuxt/interview-questions/pinia-state-management.md): 20 คำถาม, Junior - [Vuex (Legacy)](https://sharpskill.dev/th/technologies/vue-nuxt/interview-questions/vuex-legacy.md): 15 คำถาม, Mid-Level - [Composition API](https://sharpskill.dev/th/technologies/vue-nuxt/interview-questions/composition-api.md): 24 คำถาม, Mid-Level - [ระบบ Reactivity ของ Vue](https://sharpskill.dev/th/technologies/vue-nuxt/interview-questions/vue-reactivity.md): 20 คำถาม, Mid-Level - [พื้นฐาน Nuxt](https://sharpskill.dev/th/technologies/vue-nuxt/interview-questions/nuxt-fundamentals.md): 22 คำถาม, Mid-Level - [การดึงข้อมูล (Data Fetching) ใน Nuxt](https://sharpskill.dev/th/technologies/vue-nuxt/interview-questions/nuxt-data-fetching.md): 20 คำถาม, Mid-Level - [SSR และ SSG ใน Nuxt](https://sharpskill.dev/th/technologies/vue-nuxt/interview-questions/nuxt-ssr-ssg.md): 22 คำถาม, Mid-Level - [Server Routes ของ Nuxt](https://sharpskill.dev/th/technologies/vue-nuxt/interview-questions/nuxt-server-routes.md): 20 คำถาม, Mid-Level - [โมดูล Nuxt](https://sharpskill.dev/th/technologies/vue-nuxt/interview-questions/nuxt-modules.md): 18 คำถาม, Mid-Level - [Composables ใน Vue](https://sharpskill.dev/th/technologies/vue-nuxt/interview-questions/vue-composables.md): 20 คำถาม, Mid-Level - [ฟอร์มและการตรวจสอบ Vue](https://sharpskill.dev/th/technologies/vue-nuxt/interview-questions/vue-forms-validation.md): 20 คำถาม, Mid-Level - [การจัดการสถานะใน Nuxt](https://sharpskill.dev/th/technologies/vue-nuxt/interview-questions/nuxt-state-management.md): 18 คำถาม, Mid-Level - [การทดสอบ Vue](https://sharpskill.dev/th/technologies/vue-nuxt/interview-questions/vue-testing.md): 20 คำถาม, Mid-Level - [การ Deploy Nuxt และ CI/CD](https://sharpskill.dev/th/technologies/vue-nuxt/interview-questions/nuxt-deployment-cicd.md): 22 คำถาม, Mid-Level - [ประสิทธิภาพของ Vue](https://sharpskill.dev/th/technologies/vue-nuxt/interview-questions/vue-performance.md): 22 คำถาม, Senior - [รูปแบบขั้นสูงของ Vue](https://sharpskill.dev/th/technologies/vue-nuxt/interview-questions/vue-advanced-patterns.md): 24 คำถาม, Senior - [การยืนยันตัวตน Nuxt](https://sharpskill.dev/th/technologies/vue-nuxt/interview-questions/nuxt-auth.md): 20 คำถาม, Senior - [SEO ด้วย Nuxt](https://sharpskill.dev/th/technologies/vue-nuxt/interview-questions/nuxt-seo.md): 20 คำถาม, Senior - [การทำ Internationalization ใน Nuxt](https://sharpskill.dev/th/technologies/vue-nuxt/interview-questions/nuxt-i18n.md): 18 คำถาม, Senior - [สถาปัตยกรรม Vue](https://sharpskill.dev/th/technologies/vue-nuxt/interview-questions/vue-architecture.md): 22 คำถาม, Senior - [ความปลอดภัยของ Nuxt](https://sharpskill.dev/th/technologies/vue-nuxt/interview-questions/nuxt-security.md): 20 คำถาม, Senior - [ระบบนิเวศ Vue](https://sharpskill.dev/th/technologies/vue-nuxt/interview-questions/vue-ecosystem.md): 18 คำถาม, Senior - [การย้าย Vue 2→3 & Nuxt 2→3](https://sharpskill.dev/th/technologies/vue-nuxt/interview-questions/migration-vue2-vue3-nuxt2-nuxt3.md): 22 คำถาม, Senior --- Source: SharpSkill (https://sharpskill.dev), tech interview preparation for your real stack. HTML version of this page: https://sharpskill.dev/th/technologies/vue-nuxt/interview-questions/typescript-vue