Skip to content

Cannot find prop, when prop has a validator. #93

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
MatthijsBe opened this issue Mar 8, 2021 · 3 comments
Closed

Cannot find prop, when prop has a validator. #93

MatthijsBe opened this issue Mar 8, 2021 · 3 comments
Labels

Comments

@MatthijsBe
Copy link

Hi,

Just switched to volar, and so far I love it 💯.

But I got a strange error: inside an v-if I check the value of a prop, but volar will say: Cannot find name 'selectionVariant'"

the prop looks like this:

  props: {
    selectionVariant: {
      type: String,
      required: true,
      validator: function (value: string) {
        return ['dropdown', 'tiles'].indexOf(value) !== -1
      }
    }
  },

But when I remove the validator, the error is gone.

@MatthijsBe MatthijsBe changed the title Cannot find prop, when prop had a validator. Cannot find prop, when prop has a validator. Mar 8, 2021
@johnsoncodehk
Copy link
Member

Hi @MatthijsBe, I think this is defineComponent problem, you can try this:

  props: {
    selectionVariant: {
      type: String,
      required: true,
      validator: function (value: string) {
        return ['dropdown', 'tiles'].indexOf(value) !== -1
      } as never
    }
  },

@johnsoncodehk johnsoncodehk added question Further information is requested upstream and removed question Further information is requested labels Mar 8, 2021
@MatthijsBe
Copy link
Author

@johnsoncodehk Thanks it's working, closing this issue :)

@mesqueeb
Copy link
Contributor

@johnsoncodehk is there no better way to solve this besides having to manually add as never?

I spent almost half a day looking for why vue-tsc --declaration --emitDeclarationOnly doesn't emit any prop information.
Finally i know it's because a single validator in the props... 😅

Do you have ideas for a better solution for this? I'm afraid people who wanna host components on NPM and add type info on the props via vue-tsc --declaration --emitDeclarationOnly that they'll run into the same issues without knowing what's causing it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants