fix: Allow default initialization of DateTime/Duration/Interval #1643
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.
This PR default initializes the config parameter of the constructor for
DateTime
,Duration
, andInterval
in order to fix the following:This can be encountered when using a third party serialization/deserialization library such as class-transformer as temporary objects may be constructed with
new
while waiting for any transformation logic to run. This is actually a very common issue for NestJS users.Understandably, these constructors are meant to be private, but the unfortunate fact is that nothing can prevent
new
from being called on these types. Moreover, if you look at the constructor definitions it seems that the intent was to provide sane defaults already. With that in mind, it may make sense just to provide a default to sidestep the issue entirely and let the existing code handle things.Ultimately, this is a minor adjustment which fixes some very real pain points.