Skip to content

Vetur won't recognize props with a default value function #2669

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

Closed
3 tasks done
bux opened this issue Feb 3, 2021 · 2 comments
Closed
3 tasks done

Vetur won't recognize props with a default value function #2669

bux opened this issue Feb 3, 2021 · 2 comments
Labels
integ:vue3 Features specific to Vue3 upstream

Comments

@bux
Copy link

bux commented Feb 3, 2021

  • I have searched through existing issues
  • I have read through docs
  • [-] I have read FAQ Link doesn't work
  • I have tried restarting VS Code or running Vetur: Restart VLS

Info

  • Platform: Win
  • Vetur version: 0.32.0
  • VS Code version: 1.52.1

Problem

Using vue 3 and typescript

Error with default value
image

No Error when omitting the default value
image

Reproducible Case

@yoyo930021 yoyo930021 added integ:vue3 Features specific to Vue3 upstream labels Feb 5, 2021
@yoyo930021
Copy link
Member

yoyo930021 commented Feb 5, 2021

You can try to define define a return type on your default.
Ref: vuejs/vue#8679

We believe the same happens in vue 3.
Docs: https://v3.vuejs.org/guide/typescript-support.html#annotating-return-types

@bux
Copy link
Author

bux commented Feb 5, 2021

Thank you.

Using both PropType and an arrow function resolves the error message.

props: {
    elements: {
        type: Array as PropType<Element[]>,
        default: () => {
            return []
        },
    },
},

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
integ:vue3 Features specific to Vue3 upstream
Projects
None yet
Development

No branches or pull requests

2 participants