Oak-Digital / types-4-strapi-2

Automate the creation of typescript interfaces for your strapi 4 projects
MIT License
24 stars 4 forks source link

only push null if field is not required #17

Closed Roxas92 closed 2 years ago

Roxas92 commented 2 years ago

When using an field of the type "enumeration" an additional null gets pushed to the array options regardless if the field is required or not.

To ensure that null only gets pushed when the field is not required, an additional if-check is required.

Alexnortung commented 2 years ago

Thanks for sharing. This behavior is intentional, since it is technically possible for strapi to send a null value.

This happens if you create a non required field and create an entry for the given content type where the value has not been set. It can also happen of you create some entries of a type and the later add the required fields. The entry would still have a null value and thus could create runtime errors in your typescript application (which is the whole point of typescript).

This issue have been described in #14 and should be implemented as such.

I am going to close this issue, but if you still want to contribute you are much welcome. If you want to resolve your issue you can make a PR for #14. Please comment on the issue of you start working on it :)

Roxas92 commented 2 years ago

Thank you for the explanation. :) I haven't thought about it that way. But makes sense. I'll check if I can find a solution for #14 and let you know if I find something.