Add --no-optional-props #29
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
By default, properties of models which have default values will be marked as optional in the generated TS interfaces. This makes sense if you think of the TS interfaces as defining what may legally be passed into the Python model's constructor. However, if you want the TS interfaces to represent the type of the output produced by calling
.dict()
on an instance of the model, you don't want the TS interface types' properties marked optional, since they will always be there.This is particularly annoying when working with discriminated unions.
I don't think there is a general solution to this problem because the type accepted by the model constructor is actually different than the type emitted by
.dict()
, and you might want either one depending on your use case. So we add a command-line option making this behavior toggleable.This PR should provide a clean work-around for #28.