-
-
Notifications
You must be signed in to change notification settings - Fork 597
Array get error type in v-for #1790
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hmm, that's weird. If I copy and paste the virtual code into the script block, it infers correct type. |
Really weird. I also check about virtual code in project. |
If it is with explicit interface annotation, the type will be correct: import { defineComponent, computed } from '@vue/composition-api'
interface Group {
id: number
text: string
list: string[]
}
export default defineComponent({
setup() {
const groups = computed<Group[]>(() => {
const result = []
result.push({
id: 1,
text: '',
list: []
})
return result
})
return {
groups
}
}
}) |
This is also correct. import { defineComponent, computed } from "@vue/composition-api";
export default defineComponent({
setup() {
const groups = computed(() => {
const result: { id: number, text: string, list: string[]}[] = []
result.push({
id: 1,
text: '',
list: []
})
return result;
});
return {
groups
};
}
}); I think problem when typescript automatically infer types. |
I found the problem.
When noImplicitAny: true or remove this line, array will get correct type.
I think we can remove this line for respect user settings. |
Hmm, I see. I set <template>
<button @click="(event) => onClick(event)">Click</button>
</template> I guess we could just remove this option and filter implicit any errors out if it comes from template region. |
Info
Problem
Wrong:
readonly never[]
Correct:
readonly { id: number; text: string; list: never[]; }[]
PS. show virtual file is correct.
Reproducible Case
https://github.com/yoyo930021/vetur-int-bug/blob/master/src/components/HelloWorld.vue
The text was updated successfully, but these errors were encountered: