Skip to content
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

Unexpected return type of useTemplateRef with native HTML element #4801

Closed
fabon-f opened this issue Sep 4, 2024 · 1 comment
Closed

Unexpected return type of useTemplateRef with native HTML element #4801

fabon-f opened this issue Sep 4, 2024 · 1 comment

Comments

@fabon-f
Copy link

fabon-f commented Sep 4, 2024

Vue - Official extension or vue-tsc version

2.1.4

VSCode version

null

Vue version

3.5.0

TypeScript version

5.5.4

System Info

System:
    OS: Linux 5.0 undefined
    CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 0 Bytes / 0 Bytes
    Shell: 1.0 - /bin/jsh
  Binaries:
    Node: 18.20.3 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 10.2.3 - /usr/local/bin/npm
    pnpm: 8.15.6 - /usr/local/bin/pnpm

package.json dependencies

{
  "dependencies": {
    "vue": "^3.5.0"
  },
  "devDependencies": {
    "@vitejs/plugin-vue": "^5.1.3",
    "typescript": "^5.5.4",
    "vite": "^5.4.2",
    "vue-tsc": "^2.1.4"
  }
}

Steps to reproduce

Add foo.vue file with a code below. This is almost same as the example in Vue official docs.

<script setup lang="ts">
import { useTemplateRef, onMounted } from 'vue';

// the first argument must match the ref value in the template
const input = useTemplateRef('my-input');

onMounted(() => {
  input.value?.focus();
});
</script>

<template>
  <input ref="my-input" />
</template>

What is expected?

Running vue-tsc shouldn't raise an error, input.value should be inferred as HTMLInputElement | null (same as actual runtime behavior).

What is actually happening?

Raises an error below.

src/App.vue:8:16 - error TS2551: Property 'focus' does not exist on type 'InputHTMLAttributes & ReservedProps'. Did you mean 'onFocus'?

8   input.value?.focus();
                 ~~~~~

Link to minimal reproduction

https://stackblitz.com/edit/vitejs-vite-mmua2t?file=src%2FApp.vue

Any additional comments?

No response

@KazariEX
Copy link
Collaborator

KazariEX commented Sep 4, 2024

It has been fixed by #4786

@KazariEX KazariEX closed this as completed Sep 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants