1

I have a specific use case where my database record has following data

{
  id: 'user_id_1',
  '26-08-23': [{...other object}],
  '27-08-23': [{...another object}]
  ...
}

I would like to know how I can create a typescript interface to support the above case. The basic idea was to have two interfaces and see if I could extend but that doesn't work

export interface DateMappedObject {
  [date: string]: UserAttendanceDateMap
}

export interface UserAttendance extends DateMappedObject {
  id: string;
}

enter image description here

Can someone suggest a solution please?


Tldr;

Why the object is shaped this way?

  • I'm using Firebase/firestore and I'm achieving two benefits with the above object The above approach allows me to get all of that data in one query
  • The data is limited for each month, so the scalability issue is not a concern here)
  • I'll use the dates to populate a calendar with data for a day and date-key allows quick access by index-key pattern.
ady
  • 45
  • 5
  • This is a current pain point in TS and there's no perfect solution; a longstanding feature request at [ms/TS#17867](https://github.com/microsoft/TypeScript/issues/17867) to allow it, but it's not implemented. See the linked question and answers for various approaches – jcalz Aug 26 '23 at 13:20

0 Answers0