Add option to represent non-required properties as required fields in TS with | undefined
#1606
Labels
enhancement
New feature or request
help wanted
Extra attention is needed
openapi-ts
Relevant to the openapi-typescript library
Description
Proposal
I suggest adding an option that would determine whether non-required object properties get turned into:
or
The latter seems safer to work with as a producer of objects that have to match the generated TypeScript types. When adding a new non-required property to an object, I want TypeScript to point out to me all the places in which I should consider adding/skipping that property.
Right now after adding a new non-required property, TypeScript will happily accept existing code, since those existing objects are still valid, because the property is optional. If the property was declared as required, but undefinable (
| undefined
), I would have to manually go through all the places where that property should appear and either set it to a valid value, or set it tosomeProperty: undefined
(if it should be omitted).I understand this is a breaking change, which is why I suggest making it a CLI option, rather than changing the default behavior.
For reference, ts-proto has a
useOptionals
option that decides whether optional properties are generated using?
or| undefined
. They recommend| undefined
as the default behavior (the behavior I want also from openapi-typescript).Checklist
The text was updated successfully, but these errors were encountered: