vuejs / language-tools

⚡ High-performance Vue language tooling based-on Volar.js
https://marketplace.visualstudio.com/items?itemName=Vue.volar
MIT License
5.87k stars 402 forks source link

TS: issues with private class properties inside v-for #4967

Closed ludwig801 closed 3 weeks ago

ludwig801 commented 3 weeks ago

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:

<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 }:

image

Which causes:

image

Link to minimal reproduction

No response

Any additional comments?

No response

KazariEX commented 3 weeks ago

Duplicate of #4948