Closed SrBrahma closed 3 months ago
In firebase.firestore().settings({})
, there is the ignoreUndefinedProperties
:
Whether to skip nested properties that are set to undefined during object serialization. If set to true, these properties are skipped and not written to Firestore. If set to false or omitted, the SDK throws an exception when it encounters properties of type undefined.
As it doesn't fit exactly this issue, my idea is to have a setting in typesaurus like convertUndefinedToNull
, being its default true
as legacy or false
if @kossnocorp thinks it would be ok in a major. Then, if undefined, ignoreUndefinedProperties
would take place deciding what will happen.
To look similar to In firebase.firestore().settings({})
, maybe I will export from typesaurus a typesaurusSettings({})
function, allowing further options.
The undefined
behavior has been changed in v10, see the guide: https://typesaurus.com/type-safety/undefined-null/ and ADR for more info: https://typesaurus.com/decisions/adr-1-undefined
I have
db.settings({ ignoreUndefinedProperties: true, });
in my Cloud Functions to ignore undefined props, but them are being turned into null apparently by typesaurus. I just wanted to them to not be included in my update() if they are undefined.
https://github.com/kossnocorp/typesaurus/blob/7ec7091da299592751bca055bc7158e0d8ccaa2a/src/data/index.ts#L46-L47
I am now doing the following workaround, wrapping the update() data in
JSON.parse(JSON.stringify(data))
to remove the undefined props by myself.There should be a setting (or maybe check the ignoreUndefinedProperties value) to as firebase, ignore the undefined props, not throwing errors nor changing it to null.