What is the correct typing for ref<some component>
so that refVar.value.$el
is not typed as any
?
#9509
Unanswered
bbugh
asked this question in
Help/Questions
Replies: 4 comments
-
In the See #7915 (comment) |
Beta Was this translation helpful? Give feedback.
0 replies
-
<script lang="ts" setup>
import type { ComponentExposed } from 'vue-component-type-helpers';
import { nextTick, ref, onMounted } from 'vue';
const target = ref<ComponentExposed<typeof Comp>>();
onMounted(() => {
nextTick(() => {
const el = target.value?.$el as HTMLElement;
console.log(el?.clientWidth);
});
});
</script> |
Beta Was this translation helpful? Give feedback.
0 replies
-
I've been helping myself with a simple |
Beta Was this translation helpful? Give feedback.
0 replies
-
Isn't there any better way now? |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
When attempting to get the
clientWidth
of a subcomponent, I ran into an issue with typing, where even when theref
itself has the correct type,$el
is seen by TypeScript asany
. I've scoured the internet and the LLMs looking for an answer and haven't found one yet.Question: What is the correct typing for
ref
when getting the ref of a component so that$el
is correctly typed asHTMLElement
(without manually specifying it)?Here is an example:
Beta Was this translation helpful? Give feedback.
All reactions