Creating the following simple component ilustrates the problem:
<template>
<div v-for="instance of instances">
<button type="button" @click="onInstanceClick(instance)"></button>
</div>
</template>
<script setup lang="ts">
import { computed } from "vue";
class MyClass {
private privateProperty: string;
public publicProperty: string;
}
const instances = computed<MyClass[]>(() => []);
function onInstanceClick(instance: MyClass) {
//
}
</script>
What is expected?
I expected instance inside v-for to be interpreted as being of type MyClass.
Instead, it is unwrapped as { publicProperty: string }, even though instances is correctly marked as being of type MyClass[].
This problem is bigger due to the fact that it seems to be impossible to force the type of instance inside the v-for clause.
What is actually happening?
instance is being reported as being { publicProperty: string }:
Vue - Official extension or vue-tsc version
2.1.8
VSCode version
1.95.0
Vue version
3.5.11
TypeScript version
5.6.2
System Info
No response
package.json dependencies
No response
Steps to reproduce
Creating the following simple component ilustrates the problem:
What is expected?
I expected
instance
insidev-for
to be interpreted as being of typeMyClass
. Instead, it is unwrapped as{ publicProperty: string }
, even thoughinstances
is correctly marked as being of typeMyClass[]
.This problem is bigger due to the fact that it seems to be impossible to force the type of
instance
inside thev-for
clause.What is actually happening?
instance
is being reported as being{ publicProperty: string }
:Which causes:
Link to minimal reproduction
No response
Any additional comments?
No response