--- title: Always Use defineComponent for TypeScript Type Inference impact: HIGH impactDescription: Without defineComponent, TypeScript cannot infer types for props, computed properties, methods, or the 'this' context in Options API components type: best-practice tags: [vue3, typescript, options-api, defineComponent, type-inference] --- # Always Use defineComponent for TypeScript Type Inference **Impact: HIGH** - When using TypeScript with Vue's Options API, you MUST wrap your component definition with `defineComponent()` to enable proper type inference. Without it, `this` is typed as `any`, losing all TypeScript benefits. ## Task Checklist - [ ] Always import and use `defineComponent` from 'vue' for Options API components - [ ] Enable `strict: true` (or at minimum `noImplicitThis: true`) in tsconfig.json - [ ] Consider migrating to Composition API with ` ``` ## Common Mistake: Missing defineComponent This often happens when copying JavaScript components to TypeScript: ```typescript // Copied from JS - MISSING defineComponent! export default { name: 'MyComponent', // ... entire component without type inference } ``` Always add `defineComponent` when converting to TypeScript. ## Reference - [Vue.js TypeScript with Options API](https://vuejs.org/guide/typescript/options-api.html) - [Vue.js Using Vue with TypeScript](https://vuejs.org/guide/typescript/overview.html)