#transformation of ISODateString to Luxon DateTime results in error

9 messages · Page 1 of 1 (latest)

hollow wharf
#

I have the following DTO:
export class DataTableRequestDto /extends MetricDataRequestDto<TableMetricRequestDto>/ {
@ApiProperty()
@ArrayLength(2)
@Transform(({ value }) => value.map(DateTime.fromISO))
timeFrame: string[];
}

For whatever reason this transformation results in an error from Luxon
"Cannot read properties of undefined (reading 'zone') "

Any idea what's going on here?

ocean lily
#

do some debugging like this:

@Transform(({ value }) => value.map(e => { console.debug({e}); return DateTime.fromISO(e) }))
analog pulsar
#

This is a common trap with array.map(fn)

#

If fn accepts exactly one argument, this is fine

#

Buf if fn can accept multiple arguments, then these will be passed, because map passed the item, index and the entire array, respectively, as the three arguments to fn

#

Which, I presume, is the reason for the error, because DateTime.fromISO optionally accepts more parsmeters, but they are wrong

#

The simple.fix is to wrap fn into an unary lambda array.map(e => fn(e))

hollow wharf
#

Thanks for the advice guys.
I tried both of your suggestions and got the same issue.
When debugging, I noticed that the error is coming from luxon. After a couple of successful calls, somehow, luxon is called without going through the constrictor. Meaning the config is null and from there the error stems

hollow wharf
#

So the issue had to do with a package that I was using which had a module that was adding an interceptor that had the arguments "transform: true".