undefined & null
Just like in JSON, there’s no undefined
in Firestore. If you try to set undefined
, both Web SDK and Firebase Admin will throw an error unless you set an option to ignore undefined
.
However, avoiding undefined types is not always possible when working with existing types or types coming from 3rd-party. That’s why when you set undefined
with Typesaurus, it turns into null
:
That also enables you to set null
to a field that can be undefined
:
Typesaurus transforms all types and unions null
with undefined
both in write arguments and return values.
However, when consuming data from the database, the functions or components that expect original types might start showing errors:
To fix this, you can use the Nullify
helper type:
Or, when possible, add or use null
instead of undefined
: