TypeScript type used by TypeORM when dealing with Postgres timestamptz field

2 weeks ago 17
ARTICLE AD BOX

What are the consequences of using string for a timestamptz column instead of the recommended Date typing?

We are using TypeScript + Nest.js + TypeORM + PostgreSQL and want to be consistent with our Entity Date column typing for capturing datetimes. Our API layer always sends/receives such date fields as ISO UTC Strings (e.g. 2026-01-26T12:00:00Z).

Most articles (and AI responses) are telling me I need to prefer Date types to avoid issues with the way PostgreSQL formats the dates. For example:

// Date used at data layer class Entity { @Column({ type: 'timestamptz' }) dateField: Date; } // String used at API layer class Dto { dateField: string; } // Mappings required for each function entityToDto(entity: Entity): Dto { return { dateField: entity.dateField.toISOString() } } function dtoToEntity(dto: Dto): Entity { return { dateField: new Date(dto.dateField) } }

What I'm wondering is why all this is necessary (if it is) when it seems that it can be done as simply as:

// TypeORM accepts/returns strings, handles mapping to postgres class Entity { @Column({ type: 'timestamptz' }) dateField: string; } // Use custom decorator at API Layer to validate ISO UTC criteria class Dto { @IsISODateTime() dateField: string; }

We have columns in our data model that use both approaches (ugh, I know) so I know both technically work and I haven't seen any differences, but I wanted to see if anyone with more knowledge could weigh in on this decision.

Read Entire Article