language-tools: Calling prop fields in the template (like `props.foo`) doesn't work with `withDefaults`
This is issue originated from this vue/core discussion. Apparently it’s not a vue/core error.
This is the error:
Reproducible:
<script setup lang="ts" generic="T">
const props = withDefaults(defineProps<{
value?: T | null;
list: T[];
}>(), {
value: null,
});
</script>
<template>
<select>
<option v-for="item of props.list">
</option>
</select>
</template>
About this issue
- Original URL
- State: closed
- Created a year ago
- Reactions: 1
- Comments: 17 (8 by maintainers)
This works fine, I do not think it is in Vue core.
@rodrigocfd I’m working on this now, but I’m not sure if I can fix it 😂
@xiaoxiangmoe you’re still changing the type of
props
by returning them on the setup, the clean$props
are located_ctx.$props
and I would recommend using them instead.While testing this I’ve noticed Volar does not resolve the type correctly when using instance type, altho it works in the
<template>
?eg:
fixed code is
I was using v1.8.15, after updating to v1.8.18 (latest) it’s working fine. Sorry, my bad.
Thanks for the help.