TypeScript notes

To change type of a property in a new type first delete the property using Omit and then add it again. Below example changes type of _id from string to ObjectId:

type ReservationItem = {
    _id: string;
    label: string;
}

type ReservationItemDB = Omit<ReservationItem, '_id'> & {
    _id: ObjectId;
    timestamp: Date;
}

You can define type of documents read from a MongoDB collection like this:

const reservations = database.collection<ReservationItem>('reservations');