Skip to content
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

Feature request: parse validator values #9

Open
afontcu opened this issue Jan 11, 2021 · 5 comments
Open

Feature request: parse validator values #9

afontcu opened this issue Jan 11, 2021 · 5 comments

Comments

@afontcu
Copy link

afontcu commented Jan 11, 2021

Hi! And thank you for this amazing tool. I was wondering if it would be possible to parse validator values, instead of having to set a @type JSDoc comment? That would be amazing, because we'd have a single source of truth. vue-styleguidist seems to be able to do so.

Thanks! 🙌

@mesqueeb
Copy link
Member

Can you give a more concrete example ? I'm having a hard time understanding exactly what you mean :S

@afontcu
Copy link
Author

afontcu commented Jan 11, 2021

Hey! Sure :)

If I'm not mistaken, vue-intellisense requires user to define valid values for a prop:

    /**
     * The position of the action buttons.
     * @type {'top' | 'bottom' | 'right' | 'left'}  <--- this
     */
    actionButtonsPosition: {
      type: String,
      default: 'top',
      validator: (prop) => ['top', 'bottom', 'right', 'left'].includes(prop),
    },

Notice that the list of valid values is duplicated in @type and validator.

I was wondering if we could infer the options the prop from the validator array, so the following snippet would yield the same vetur config as the one above:

    /**
     * The position of the action buttons.
     */
    actionButtonsPosition: {
      type: String,
      default: 'top',
      validator: (prop) => validValues.includes(prop), // @type is inferred from here
    },

@afontcu
Copy link
Author

afontcu commented Jan 20, 2021

Hi! I checked and noticed that this works:

    /**
     * The position of the action buttons.
     */
    actionButtonsPosition: {
      type: String,
      default: 'top',
      validator: (prop) => ['top', 'bottom', 'right', 'left'].includes(prop),
    },

so I assume the limitation is with using a variable to set the array?

@afontcu
Copy link
Author

afontcu commented Jan 26, 2021

I'll go ahead and close this issue since this looks like an upstream limitation :) Tracked here: vue-styleguidist/vue-styleguidist#1049

@afontcu afontcu closed this as completed Jan 26, 2021
@mesqueeb
Copy link
Member

mesqueeb commented Mar 8, 2021

@afontcu I'm so sorry I never replied. I got super busy and always forgot to come back to this.

this looks like an upstream limitation :)

this is exactly right!! : ) Under the hood I use the vue-styleguidist API : )

even though it's upstream, let's keep this issue open so I don't forget ;)

@mesqueeb mesqueeb reopened this Mar 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants