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

Conflict between shouldExtractLiteralValuesFromEnum and shouldRemoveUndefinedFromOptional #341

Closed
theAdhocracy opened this issue Apr 12, 2021 · 3 comments

Comments

@theAdhocracy
Copy link

In the latest version of Storybook (6.2), props with an enum/string literal typing are incorrectly displaying undefined on the Controls panel (what used to be the Knobs addon).

It looks like the culprit is a conflict between the shouldExtractLiteralValuesFromEnum and shouldRemoveUndefinedFromOptional option flags. Storybook currently has both set to true, but the conversion to enum is outputting a value that takes priority over the string with undefined removed.

Honestly, I'm over my head debugging this (😅) but it seems to me that this part of parser.ts:

value: propType.types.map(type => ({
   value: this.getValuesFromUnionType(type)
}))

Could have a conditional that checks whether shouldRemovedUndefinedFromOptional is true and then filters out undefined values from the enum.

Related issue on Storybook for full context: storybookjs/storybook#14523

@michelengelen
Copy link
Contributor

I will have a look next week (probably monday) ... should be a relatively easy fix

@michelengelen
Copy link
Contributor

Soooo ... I had a look and the problem is, that I could not find a single case where "undefined" gets added to the propTypeString in the tests. So I created a new component and tested some things out ... turns out that the package itself does not add the | undefined by default.

You were right with the code block you mentioned. I can only suspect, that there is some kind of edge-case in the storybook implementation.

I will continue looking into this though. 🚀

@pvasek
Copy link
Collaborator

pvasek commented Jun 9, 2021

This should be fixed in v2.0.0 release.

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

3 participants