Open Alexnortung opened 2 years ago
Great work Alexnortung... very usefull your script
I would like to have a non-paranoid flag, and make sure all required fields have non-nullable types in the generated types
Thanks for the feedback @ppemond-bkom , and sorry for the late answer. We are busy with a lot of other things and this issue is sadly not a priority right now. If you have the time and skills you are welcome to open a PR.
Strapi allows for required fields, if a required field is used on a content-type or component it makes sense to create a typescript interface which has that field as a non-nullable value. And if it is not a required field, it makes sense to create the interface with a nullable type.
There is just one problem: It is possible to change the field from not required to required after its first creation. This may now lead to inconsistencies and the interface can no longer be guarenteed to be correct. This can then later lead to runtime errors, which kind of defeats one of the purposes of using typescript in the first place.
Possible solution: Keep the current implementation and add a paranoid flag, which makes all required fields nullable, in the generated interface.
Another solution: Change the default implementation to use the suggested paranoid approach and add a non-paranoid flag for the fearless users.