Replies: 2 comments
-
Hey there, @areindl! I'm a bot here to help you with bug fixes, questions, and contributions. Let's tackle this challenge together! 🤖 To handle the type inference issue with
onClickOutside(overlayPanel as unknown as MaybeElementRef, () => overlayPanel.value?.hide(), {
ignore: ['.p-overlaypanel'],
})
const overlayPanel = useTemplateRef<OverlayPanel & HTMLElement>('overlayPanel') Both methods aim to align the type of |
Beta Was this translation helpful? Give feedback.
-
You can use it like this const overlayPanel = useTemplateRef<InstanceType<typeof OverlayPanel>>('overlayPanel')
onClickOutside(overlayPanel, () => {
console.log('clicked outside')
}) refrence: https://vuejs.org/guide/typescript/composition-api.html#typing-component-template-refs |
Beta Was this translation helpful? Give feedback.
-
Vue's new useTemplateRefs() i is great. It brings a long more typesafetly and explicitness to the code.
However, I am fighting a bit with the new Type-Inference.
Example:
I am using a templateRef and declared it here it here:
It simply references a custom OverlayPanel-Component:
Now I want to leverage the onClickOutside() function from vueUse:
But onClickOutside expects a
MaybeElementRef
type. Through the type-inference, my templateRef is now of typeReadonly<ShallowRef<OverlayPanel | null>>
- before it wasany
.How would you handle this? Any proposals?
One thing that works is: Intersection Type using
&
operatorThanks a lot 🎉
Beta Was this translation helpful? Give feedback.
All reactions