Skip to content

Inferred useTemplateRef type is incorrect when used in v-for #5320

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

Closed
mdoesburg opened this issue Apr 15, 2025 · 1 comment
Closed

Inferred useTemplateRef type is incorrect when used in v-for #5320

mdoesburg opened this issue Apr 15, 2025 · 1 comment
Labels
good reproduction ✨ This issue provides a good reproduction, we will be able to investigate it first

Comments

@mdoesburg
Copy link

mdoesburg commented Apr 15, 2025

Vue - Official extension or vue-tsc version

2.2.4

VSCode version

1.99.2

Vue version

3.5.13

TypeScript version

5.4.5

System Info

System:
    OS: macOS 15.3.2
    CPU: (10) arm64 Apple M1 Pro
    Memory: 91.69 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.11.1 - ~/.nvm/versions/node/v20.11.1/bin/node
    Yarn: 1.22.19 - /opt/homebrew/bin/yarn
    npm: 10.2.4 - ~/.nvm/versions/node/v20.11.1/bin/npm
    pnpm: 9.15.5 - ~/Library/pnpm/pnpm
    Watchman: 2022.12.05.00 - /opt/homebrew/bin/watchman
  Browsers:
    Chrome: 135.0.7049.95
    Edge: 135.0.3179.73
    Safari: 18.3.1

package.json dependencies

Steps to reproduce

  1. Create the following components:

Component1.vue

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

import Component2 from './Component2.vue';

const components = useTemplateRef('component2');
</script>

<template>
    <div v-for="n in 5" :key="n">
        <Component2 ref="component2" />
    </div>
</template>

Component2.vue

<template>
    <p>Test</p>
</template>
  1. See that the components type is incorrect:
Image
  1. Downgrade to [email protected] and see that the components type is correct (it correctly infers an array):
Image

Note:

This seems to only be an issue when placing the ref inside of the slot. Placing it on the root v-for element seems to work correctly:

<template>
    <Component2 v-for="n in 5" :key="n" ref="component2" />
</template>

What is expected?

I expect the type to correctly infer an array of elements and/or components. See: Refs inside v-for

What is actually happening?

The type infers a single element and/or component instead of an array.

Link to minimal reproduction

No response

Any additional comments?

No response

@KazariEX KazariEX added good reproduction ✨ This issue provides a good reproduction, we will be able to investigate it first and removed pending triage labels Apr 16, 2025
@KazariEX
Copy link
Member

This has been fixed by #5278.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good reproduction ✨ This issue provides a good reproduction, we will be able to investigate it first
Projects
None yet
Development

No branches or pull requests

2 participants