Change how generation of optional types works #14
aaronrosenthal
started this conversation in
Ideas
Replies: 1 comment 1 reply
-
Hi Aaron! Thanks for the thoughtful discussion. Adding support for For example, SQL columns without defaults would either have a value or end up as On the other hand, conditional attributes would be |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Currently the library generates interfaces using TypeScript's shorthand for optional parameters, but I believe this is incorrect or at the very least should be configurable.
For example, these two are equivalent:
Generally serializers are going to be used to render JSON in a controller, and since JSON doesn't serialize
undefined
values (onlynull
values), I think the above behavior could be improved. Without any changes, the only workaround I've been able to find would be doing something like:or simply leave it out of the serializer with:
neither of which are ideal as they lead to a lot of extra boilerplate, especially for types inferred from the schema.
What are thoughts on this? I suggest one (or both) of two solutions:
Solution 1
Configuration setting to change the global behavior so that all optional parameters are generated in a syntax like the following:
or perhaps:
so
undefined
values are also considered. This could look something like the following, where we can specify whether to use just undefined (this would be the default, and could continue to generate shorthand syntax), just null, or both:Solution 2
An option in
oj_serializer
to by default exclude allnull
values in serialized responses (so they actually would beundefined
in TypeScript):Beta Was this translation helpful? Give feedback.
All reactions