Effect CommunityEC
Effect Community2y ago
10 replies
Guido

Creating a Firestore Schema with Timestamp Fields for TypeScript Validation

one question, I'm trying to create a schema for a firestore collection and i don't know how to do timestamp fields.

i want to have everything schema validated and use them to generate typescript types from it

firestore types it like this:
export class Timestamp {
  constructor(seconds: number, nanoseconds: number);
  static now(): Timestamp;
  static fromDate(date: Date): Timestamp;
  static fromMillis(milliseconds: number): Timestamp;
  readonly seconds: number;
  readonly nanoseconds: number;
  toDate(): Date;
  toMillis(): number;
  isEqual(other: Timestamp): boolean;
  valueOf(): string;
}


How can i create a schema with a createdAt field?

What would be the best way to do this if my approach is wrong?

Do I need to do some custom validation?
Was this page helpful?