I'm facing an issue with saving incomplete forms where I have a form being filled out by a user and I wish to allow the form to be saved even if it's not fully complete.
Before sending the object to my API, I need to set any null attributes to either 0 or an empty string depending on whether the attribute is supposed to be a number or a string. If this isn't done, the API won't accept the object.
The current approach I am trying involves:
for (const property in this._object) {
if (this._object[property] == null) {
//need assistance in determining if [property] should be treated as a string or a number
}
}
Since typeof check doesn't work on null values, I am unable to distinguish between strings and numbers when properties are null. Is there a way to figure out the type of an object that is currently null? All properties are strongly typed in the object class so TypeScript knows their types at compile time.