A better setup?

I’ve only done a couple of projects from scratch implementing databases such as MongoDB, and I’ve used DAOs to manage those operations. I want to explore moving away from this pattern as I work more in the Functional Programming paradigm.

I thought this MongoDB blog entry would be a good starting point, but the approach for setting up the collections isn’t really type safe, or more accurately, it is configured in such a way that the programmer would have to check the existence of each collection every use, and that seems inefficient.

export const collections: { games?: mongoDB.Collection } = {}

By making each individual collection optional, the programmer has to check to ensure the collection is defined before each use. Sure we could use a non-null assertion, but that seems wrong.

What are some other ways to set up this global collections so that the expected collections are defined when created. Or perhaps there is a way to do better with the Typescript?

But I’m not lookin for tricks to obfuscate the issue; I want to write better code.