null over undefined
Unless you have existing code relying on undefined
, can’t have exactOptionalPropertyTypes
enabled, or want to use types that you can’t control or don’t want to change, it’s better to use null
when designing your schema.
The reason for that Firestore, just like JSON and many other programming languages, doesn’t have the undefined
type. So when you try to write undefined
to Firestore, it will throw an error unless you set an option to ignore it, making it a source of runtime errors.
However, when you set undefined
with Typesaurus, it turns into null
:
So make your life easier and use null
instead of undefined
in your schema unless you have to use it:
Note that even though lastName
is optional, Typesaurus recognizes it (as long as you have exactOptionalPropertyTypes
enabled) and will force you to set null
, string
, or $.remove
helper: