This PR default initializes the config parameter of the constructor for DateTime, Duration, and Interval in order to fix the following:
Cannot read properties of undefined (reading 'zone')
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.
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.