Typing Composables and Refs
Ref , ComputedRef , typed return from composables, MaybeRef .
Typing the Composition API
Composables are just functions, and refs are just typed containers. Adding explicit types makes your composables safe to consume and gives callers full autocomplete.
Inferred ref Types
Most of the time TypeScript infers a ref type from its initial value. A ref(0) is a Ref<number> automatically.
import { ref } from 'vue'
const count = ref(0) // Ref<number>
const name = ref('Coddy') // Ref<string>All lessons in this course
- TypeScript Setup in Vue Projects
- Typed Props and Emits with defineProps/defineEmits
- Typing Composables and Refs
- Generic Vue Components