ts-plugin(6133): Template refs from composables incorrectly flagged as unused
Vue - Official extension or vue-tsc version
3.2.1
VSCode version
Cursor 2.2.43 (VSCode Version 1.105.1)
Vue version
3.5.25
TypeScript version
5.9.3
System Info
System:
OS: Linux 6.6 Ubuntu 24.04.3 LTS 24.04.3 LTS (Noble Numbat)
CPU: (20) x64 12th Gen Intel(R) Core(TM) i7-12700K
Memory: 8.28 GB / 15.51 GB
Container: Yes
Shell: 5.2.21 - /bin/bash
Binaries:
Node: 22.21.1
Yarn: 1.22.22
npm: 11.6.4
pnpm: 10.26.2
package.json dependencies
{
"dependencies": {
"@modelcontextprotocol/sdk": "^1.23.0",
"color-bits": "^1.1",
"ofetch": "^1.4",
"overlayscrollbars": "^2",
"overlayscrollbars-vue": "^0.5",
"zod": "^4.1.13"
},
"devDependencies": {
"@stylistic/eslint-plugin": "^5.6.1",
"@types/node": "^24.9",
"@unhead/vue": "^2.0.19",
"@vue/test-utils": "^2.4.6",
"autoprefixer": "^10.4.22",
"eslint": "^9.39.2",
"eslint-plugin-perfectionist": "^5.1.0",
"eslint-plugin-vue": "^10.6.2",
"jsdom": "^27.3.0",
"msw": "^2.12.4",
"stylelint": "^16.26.1",
"stylelint-config-recommended-vue": "^1.6.1",
"stylelint-config-standard": "^39.0.1",
"stylelint-order": "^7.0.0",
"tailwindcss": "^4.1.18",
"ts-morph": "^27.0.2",
"tsx": "^4.20.6",
"typescript-eslint": "^8.49.0",
"unplugin-vue-components": "^30.0.0",
"vite": "^7.2.7",
"vite-plugin-dts": "^4.5",
"vitest": "^4.0.15",
"vue": "^3.5.25",
"vue-router": "^4.6.4",
"vue-tsc": "^3.2.1",
"vue3-gettext": "^4.0.0-beta.1"
}
}
Steps to reproduce
- Create a Vue composable that returns template refs:escript
// use-drawer.ts
export function useDrawer(...) {
const drawerRef = ref<HTMLElement | null>(null);
const containerRef = ref<HTMLElement | null>(null);
// ... other refs
return {
drawerRef,
containerRef,
// ... other refs
};
}
- In a Vue SFC component, destructure refs from the composable:
<script setup lang="ts">
const {
drawerRef,
containerRef,
// ... other refs
} = useDrawer(...);
</script>
<template>
<div ref="drawerRef">
<div ref="containerRef">
<!-- content -->
</div>
</div>
</template>
- Open the component in IDE - TypeScript plugin reports unused variable errors (even with
noUnusedLocals: falseintsconfig.json)
What is expected?
Template refs that are destructured from composables and used in the template via ref="xxx" should not be flagged as unused variables. The TypeScript plugin should recognize that these refs are used in the template, even when they come from a composable return value. This was never an issue until recently.
Note: This appears to be related to the v3.1.1 change that uses RefSymbol property to detect refs. When refs are destructured from composables, the plugin may not be able to detect the RefSymbol property correctly. This is just conjecture after I grepped the change logs.
What is actually happening?
The TypeScript plugin (ts-plugin) is reporting unused variable errors (ts-plugin(6133)) for template refs that are:
- Destructured from a composable return value
- Used in the template via
ref="xxx"attributes - Not explicitly referenced in the
<script>section
The error message is: 'containerRef' is declared but its value is never read. ts-plugin(6133)
This occurs even when noUnusedLocals: false is set in tsconfig.json, indicating the plugin has its own unused variable detection logic that bypasses the TypeScript compiler setting.
The variables are also grayed out in the IDE, making it appear as if they're truly unused when they're actually being used in the template.
Note: This appears to be related to the v3.1.1 change that uses RefSymbol property to detect refs. When refs are destructured from composables, the plugin may not be able to detect the RefSymbol property correctly. This is just conjecture after I grepped the change logs.
Link to minimal reproduction
No response
Any additional comments?
As far as I can tell, this appears to be an issue with Vue Language Tools. I apologize in advance if this is an upstream issue.
If you're going to mark this as a duplicate, then you need to acknowledge that THIS IS A BUG. You are breaking an architectural paradigm by not fixing this. https://github.com/vuejs/language-tools/issues/5815#issuecomment-3691432775