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

required Single-Option type includes redundant empty string #8

Open
blindfish3 opened this issue Jul 6, 2022 · 4 comments
Open

required Single-Option type includes redundant empty string #8

blindfish3 opened this issue Jul 6, 2022 · 4 comments

Comments

@blindfish3
Copy link

In Storyblok I have a Single-Option field that is required and has a default value set. It's for a form button so the options are button and submit. When I run storyblok-generate-ts the definition for this field is as follows:

buttonType: "" | "button" | "submit";

In this case the empty string is not a valid option for this field and should not be included in the generated type.

@dohomi
Copy link
Owner

dohomi commented Jul 7, 2022

@blindfish3 this PR made the empty string possible and I haven't encountered any issue with that:
#5

@blindfish3
Copy link
Author

OK - I now see how to exclude the empty string; but It doesn't really make a lot of sense to me.

So, to resolve this issue you can tick the "Hide empty option" checkbox in Storyblok and then the empty string is removed from the type. In the interface that option hides any empty option that is added.

The problem I have with that solution is that - in Storyblok - that checkbox only has an effect if an empty option is included. In my case there is no empty option; so I don't need to tick the box and I don't expect to see one in the types:

image

Here I would expect buttonType: "button" | "submit";

image

Here the empty string would be expected: buttonType: "" | "button" | "submit";

image

Where there is an empty option but "Hide empty option" is ticked I would again expect buttonType: "button" | "submit";

Does that make sense?

@dohomi
Copy link
Owner

dohomi commented Jul 7, 2022

I think your point of view just collides with the PR from other users who want to have an empty option string. So fundamentally I guess it needs to be an option to en- or disable the empty string. Feel free to open a PR for your use case and I will have a look.

@blindfish3
Copy link
Author

I think your point of view just collides with the PR from other users who want to have an empty option string

I don't think so: I'm just saying that the empty string option should only find its way into the type when it is a possible input value; and that isn't the current behaviour.
Anyway for now I just have to remember to tick "Hide empty option". I'll have to check if I can find some time to raise a PR.

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