Based on the information provided in the documentation, it is recommended that a Date
object be converted to a string
:
It's important to note that dates will automatically be converted to strings when attempting to convert a class object to a plain object.
However, my code example using class-transformer version 0.2.3
is not behaving as expected:
class TestDate {
@Type(() => Date)
aDate!: Date;
}
const testDate = new TestDate();
testDate.aDate = new Date();
const result: any = classToPlain(testDate);
console.log(typeof result.aDate);
When running this code, the console output shows object
instead of the expected string
. Have I overlooked something?