Firestore allows to query documents across different collections as long as they have the same name.
To use this feature with Typesaurus, import groups function that wraps the database instance:
The database wrapper recursively extracts all collections, giving you access to them on the root level even if they are deeply nested:
And just like anything else in Typesaurus, collection groups are 100% type-safe. When you query a group that has a variable model shape, the return data type will consider that:
If this example querying posts collection got us both Post and UserPost documents, we must narrow down the type to access the unique highlight field. All the shared fields are accessible without narrowing down.