-
-
Notifications
You must be signed in to change notification settings - Fork 443
Bug: ref typings should be inferred from element tag #342
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
You should define correct type param to ref, and make sure your vue version >= 3.2, because vue 3.1.5 has a type bug in this case. <template>
<ul :ref="el => state.element = el"></ul>
</template>
<script lang="ts" setup>
import { ref, ComponentInternalInstance } from 'vue'
const state = ref<{ element: ComponentInternalInstance | Element | null }>({ element: null })
</script> Btw <template>
<ul :ref="el => {
// @ts-ignore
state.element = el
}"></ul>
</template>
<script lang="ts" setup>
import { ref } from 'vue'
// @ts-ignore
const state = ref<{ element: Element }>({ element: null })
</script> |
The problem is, the CORRECT type param to ref is |
Please don't say that, you are not to please volar, you to please typescript. You can reproduce same errors in the // foo.tsx
import { ref } from 'vue'
const state = ref<{ element: Element }>({ element: null })
const _ul = <ul ref={el => state.element = el}></ul> |
Uh oh!
There was an error while loading. Please reload this page.
This will produce error because
ComponentInternalInstance | Element
cannot be assigned toElement
.However we can infer the real
:ref
isstring | Ref<any> | ((ref: HTMLUListElement) => void)
instead ofstring | Ref<any> | ((ref: ComponentInternalInstance | Element) => void)
becauseul
is hard-coded.Or, can we prevent the error message by
<!-- @ts-ignore -->
or something?The text was updated successfully, but these errors were encountered: