-
I've started doing this with my types and I'm not sure that it is the best. type GroupWithoutID = {
labels: { [uid: string]: string },
participants: string[],
};
export type GroupMetaType = MetaTypeCreator<
GroupWithoutID,
'groupsCollection'
>
export type Group = GroupWithoutID & ID; The reason for this is that when I get data from the database I have to do something like this: group = document.data() but if I want the document id of the group I need to call document.id usually in my code, when I want data, I just want a flat object: {...document.data(), id: document.id} so that I don't have to carry the document and the data around separately. The result is that I end up needing three types as you see at the beginning of this post.
Is this an OK pattern? Am I missing anything? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
a more accurate and reusable type would be type GroupWithoutID = {
labels: { [uid: string]: string },
participants: string[],
};
export type GroupMetaType = MetaTypeCreator<
GroupWithoutID,
'groupsCollection'
>
export type Group = GroupMetaType['read'] & { id: GroupMetaType['docID'] };
normally document id type is string but it is possible to assign literal type like Meta type is your single source of truth, more about meta type https://firelordjs.com/guides/metatype#index-accessor |
Beta Was this translation helpful? Give feedback.
a more accurate and reusable type would be
data()
always returnread
typenormally document id type is string but it is possible to assign literal type like
abc${string}123
to document id type, so it is better to read document id type from meta typeMeta type is your single source of truth, more about meta type https://firelordjs.com/guides/metatype#index-accessor