-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
What is the right way to declare type for data object, passed to updateDoc? #89
Comments
By design Firelord enforce common best practice, one of the practice is no optional because of this reason I strongly recommend that during MetaType creation, use default value of other type type __HERE__ = {name: string | false, age: number | false }
type ABC = MetaTypeCreator< __HERE__ , "abc">
const dataObject: __HERE__ = { name: false, age: false};
I do not recommend
there is even a setting to ban the use of |
optional is one of the highly requested features because it is very common Typescript feature Firelord does not support optional to prevent user from accidentally cripple their query capabilities in long term This of course make some developers feel uncomfortable Currently I am brainstorming whether we can achieve a middle ground in V3, but that is very unlikely because Firelord aim to be the safest wrapper(but will still allow optional in update operation), I will also probably ban the use of hopefully in V3 update ca accept something like |
after giving it a deeper thought, my suggested solution does not work I need time to patch up a solution meanwhile you can use |
Thanks for the response, but I'm not talking about optional props, all props in my MetaType are not optional, but i want to have a Type, that have one or more of those all props. Here are more parts of code to make clarify my issue: MetaType Creation: type FirestoreChatData = {
_uid: string;
name: string;
//
update_action: UpdateAction;
//
created_at: ServerTimestamp;
creator_uuid: string;
created_by_platform: string;
//
updated_at: ServerTimestamp;
updated_by_uuid: string;
updated_by_platform: string;
//
deleted_at: ServerTimestamp | null;
deleted_by_uuid: string | null;
deleted_by_platform: string | null;
};
export type ChatsMetaType = MetaTypeCreator<FirestoreChatData, 'Chats'>; Then this works updateDoc(ref, {
name: 'New Name',
}); But this doesn't, I've expected, that Partial will do the job, but const data: Partial<ChatMetaType['write']> = {
name: 'New Name',
};
updateDoc(ref, data) About undefined props: why just not drop them when updating doc? |
please do release note: https://github.com/tylim88/FirelordJS/releases/tag/2.2.0 |
you must turn on
they are needed to explain stuff before the era of |
Thanks for quick resolving!! And for exposing types too, wanted to ask about it, but forgot)) |
Hello, firstly, thank you for amazing library that makes everything easier!!!
I have some trouble:
I need to implement a helper function, that makes it possible to not add some required parameters in every call of
updateDoc/batch.update
, and I'm unable to figure out, what type ofFirestoreUpdateParams.data
parameter should be to pass the typescript validation, and, more importantly, throw errors, if I'm passing wrong data to this helper function.Here is the code:
Expecting to use it like this:
But this type would be also useful when creating data object in few places step by step
The text was updated successfully, but these errors were encountered: