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 407 forks source link

v-for 多个类型推导为 item: unknown #4812

Open wxwebfeng opened 2 months ago

wxwebfeng commented 2 months ago

Vue version

3.5.0

Link to minimal reproduction

https://play.vuejs.org/#eNp9U81u00AQfpVhL0lRyH96CE4kQJUIohQBEodsDq69Tja1d63ddUjlWkICqRckroCExIVzX6CoL0NLeAvGayckEvRizXzzzef525Q8iOP6ImGkTxztKR4b0MwkMYSumA4oMZqSIRU8iqUykIIUhzIRhvmQQaBkBBVMrtzfYigW1PDjeoYv2A6LCqRhrgpcj8HIsAhSKgC43weRRMdMwRloo7iYUpHtcEUgj47nBX18wk77JW/StzqWbk7jgvmUawMDGxhPqPCkQD/SU8SwuGrlMQtDCa+lCv07lT0qGg1YXX3+ff7h+uPF6t2Pm08XECsZa/h5+W11dX7z9fuvL++v317CWst3jVuIOZv/na2LHFbHExSFfI6jvIOFG1arezAYFuUDFCLYMWocumZWD0IpVdWayhW+jJB+F1pNK4PzCaCas4eDHuytRcBWUUfxhKHOBgUwfUjzkbZaWW0LbZdwu70Dd0q408ERFlhpZMBCzf7zv7FN6nazmjV6vdLY389w5BuVrAadZjNvxGkU54XHhA6uJg5dw9ADcGatYZraDWWZ00DPoj5fwOJeIBWeIc+PhQtbAyXQxxMo0Tr3EcD80skVMBMlnMbWX0gNTxkHH/Bpfa6lwHu3jVHiySjmIVNHseG4GEpwIEUHlLh4KG+eWMyohJVzw5wZ807+gc/1Mscoea6Yxs0zSjYx46opM0X44OUztkR7E4ykn4TIviX4gmkZJnmNBe1hInwse4tnqx3Zd4hP45U+WBom9LqpvNBiJUXf+CIf3dL633I79a7Nw0dGsj/zRmUR

Steps to reproduce

vue vfor ts unknown

将v-for 的类型 设置为 数组对象 或者 对象嵌套 对象, 出现 类型为 unknown 情况

What is expected?

期望 能够 推断出其类型 , 就是上面用例中的 Item

What is actually happening?

其实给出了 类型为 unknown

System Info

No response

Any additional comments?

No response

Shyam-Chen commented 2 months ago
const infos = ref<Info[]>([]);

You need to convert infokey and Info into an Info[] array based on your own judgment criteria.


Or render separately:

<template v-if="Array.isArray(data)">
  <div v-for="item in data" :key="item.id">{{ item.id }}</div>
</template>

<template v-else>
  <div v-for="(val, key) in data" :key="val.id">{{ val.id }}</div>
</template>
baiwusanyu-c commented 2 months ago

const data = ref<InfoList | InfoObj[]>([])

yyx990803 commented 2 months ago

This should be in the scope of language tools and how v-for codegen works. Transferring over.

robokozo commented 3 weeks ago

I'm seeing similar things. image image

I'm in a VS Code Remote session image

I've started seeing this error yesterday. Could it be related? image

Rolling back Vue Official to 2.1.6 fixed it for me

robokozo commented 3 weeks ago

@wxwebfeng upgrading to v2.1.10 fixed my issue. is yours resolved?