Skip to content

In some cases, the return type of useTemplateRef is inferred as any #13886

@jss-tg

Description

@jss-tg

Vue version

3.5.21

Link to minimal reproduction

https://play.vuejs.org/#eNqNU12P2jAQ/CsrvwAqTXSlJ1UIOPWDh1YqPV1RnyxVPrIBXxPbsp0UFOW/d+2QlKLTqU/YM+Pd2c3QsPfGJHWFbM4Wbmel8eDQVwYKofZLzrzjbMWVLI22HhqoHG6xNIXw+IA5TGGnS1N5zFrIrS5hRLVGg/6TdCQ9bc5ckvZAaEkyrtIUtgcEfzIIOgd/kA5qYaV4LBDoLFWO1mIGwoFQJ652Wjkfu4b+yytD49GZGU16aYaFFyS86QFFl971eDyB5aovl9SiqPAu2aPfjCdUYZF2O6EN0MWf+9ANYDHMZjGnRZ1LcAbz2JGg+EtA2j2QilpC/brURBCtOAvMIr2oy6a0cbKZy33y5LSiz9KEx119WaD9ZrykMTibQ2QCJ4pC//4SMW8rnPb47oC7X8/gT+4YMM7uLTq0NXI2cF5YGr+j1983eKTzQJL1qiD1C+QDOl1UwWMn+1CpjGxf6KLbzzEgUu23bn30qFw/VDAalG3Uc0ZB+fjC6H/tzpK38R1XLW3xMmj/me3nk9xlxlhtHOUmw1wqvA+3RRO/790cVFU+om1X4yFz1xmjiMUKSRfGV/BV+ENihcp0GYPGVVd5fTTa4biBEME5dOlUXS6h/TeRV3nMZB0PMPzraE0NOWlpJcSnneA6bj9rtGH5tKRZcpu8uQmYdz8G9DZ5l8xY+wfOF2cp

Steps to reproduce

<script setup lang="ts">
import { useTemplateRef , computed} from 'vue'
import DisplayN from './DisplayN.vue'

// The type of this variable is inferred as any
const compRef = useTemplateRef('compRef')
const delta = 1
const n = computed(() => compRef.value?.getN())
</script>

<template>
  <DisplayN ref="compRef" :delta="delta" />
  <input v-model="n"/>
</template>

See Demo for details

What is expected?

Automatically infer the type of compRef

What is actually happening?

compRef is inferred as any.

System Info

Any additional comments?

If you removev-model="n" or :delta="delta", the type of compRef can be inferred correctly.🫠

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions