You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In both cases, vue-tsc should automatically infer the type of the input template ref as HTMLInputElement, and so it accepts input.value?.focus() because HTMLInputElement has a focus method.
What is actually happening?
In the <script setup> case, inference works correctly. But in the defineComponent case, vue-tsc does not infer the type of the input template ref, resulting in a TypeScript error for input.value?.focus(), because the type of input.value is unknown.
Link to minimal reproduction
No response
Any additional comments?
No response
The text was updated successfully, but these errors were encountered:
Just as you cannot use the define macros at there, type inference for useTemplateRef and so on is only implemented in script setup, otherwise the code will be too complex.
Vue - Official extension or vue-tsc version
2.1.10
VSCode version
N/A
Vue version
3.5.13
TypeScript version
5.7.2
System Info
package.json dependencies
No response
Steps to reproduce
Bind a template ref to a native HTML element in a component that uses
<script setup>
:Then write the same code, but using
defineComponent
:What is expected?
In both cases, vue-tsc should automatically infer the type of the
input
template ref asHTMLInputElement
, and so it acceptsinput.value?.focus()
becauseHTMLInputElement
has afocus
method.What is actually happening?
In the
<script setup>
case, inference works correctly. But in thedefineComponent
case, vue-tsc does not infer the type of theinput
template ref, resulting in a TypeScript error forinput.value?.focus()
, because the type ofinput.value
isunknown
.Link to minimal reproduction
No response
Any additional comments?
No response
The text was updated successfully, but these errors were encountered: