Vue · Senior · Question 38 of 75
How do you type a template ref to a child component?
const modal = useTemplateRef<InstanceType<typeof Modal>>("modal");
modal.value?.open();- ✓Correct answer: Use
InstanceType<typeof Component>; only properties exposed withdefineExposeare available - 2Template refs to components are always
any - 3Use
HTMLElementfor every ref
Explanation
The value is null before mount, hence optional chaining. Prefer props/events over calling child methods; exposing methods is for imperative APIs like focus() or open().