Replies: 1 comment 1 reply
-
Not sure what you mean with manually, you'd type the ref based on the component, same as native elements.
Of course, it being automatic would be neat. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
There is a simple situation below.
A component in template and a ref in script.
Ref is binded to component.
But ref doesn't infer type of what the component exposes.
It's of type
any
.In case we bind a ref to any html element it's pretty easy to set the same type to ref (for example
ref<HTMLDivElement>()
) as all of them are predetermined.But in case we bind a ref to a component we have to describe a type manually.
`<script setup lang="ts">
import { getCurrentInstance, ref } from 'vue';
import VComp from './Comp.vue'
const a = getCurrentInstance()
a.refs.myComp
const myComp = ref()
`</script>
Would be great to have ref's able to auto infer types of what they are binded to
A simple reproduction
Beta Was this translation helpful? Give feedback.
All reactions