storyblok-generate-ts
storyblok-generate-ts copied to clipboard
required Single-Option type includes redundant empty string
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.
@blindfish3 this PR made the empty string possible and I haven't encountered any issue with that: https://github.com/dohomi/storyblok-generate-ts/pull/5
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:
Here I would expect buttonType: "button" | "submit";
Here the empty string would be expected: buttonType: "" | "button" | "submit";
Where there is an empty option but "Hide empty option" is ticked I would again expect buttonType: "button" | "submit";
Does that make sense?
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.
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.