Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork68
how to handle optional properties correctly?#572
-
I am storing an object I receive from another API/Library. One of the properties is optional. When passed to Here is my schema: exportconstDISPLAY_USER_INFO_JSON_SCHEMA:JSONSchema={type:'object',properties:{firstName:{type:'string'},lastName:{type:'string'},name:{type:'string'},partner:{type:'string'},passwordExpiration:{type:'string'},username:{type:'string'},},required:['name','partner','username'],// i originally did not have that, but that did not help}; and here is my data from IndexDB: firstName:"Eric"lastName:"Liprandi"name:"Eric Liprandi"partner:"snapfish"passwordExpiration:undefinedusername:"ericl" I tried returning How can I handle this situation directly with the library? |
BetaWas this translation helpful?Give feedback.
All reactions
Hi,
Currently, the JSON validator in the lib expects optional object properties to be inexistant:
constuser={firstName:"Eric",lastName:"Liprandi",name:"Eric Liprandi",partner:"snapfish",username:"ericl"};
If it's not possible to directly get that from your other API, you can do:
constuser={firstName:"Eric",lastName:"Liprandi",name:"Eric Liprandi",partner:"snapfish",passwordExpiration:undefined,username:"ericl"};if(user.passwordExpiration===undefined){deleteuser.passwordExpiration;}
Given that in TypeScriptpasswordExpiration?: string is equivalent topasswordExpiration: string | undefined, it would make sense to allow explicitu…
Replies: 1 comment 1 reply
-
Hi, Currently, the JSON validator in the lib expects optional object properties to be inexistant: constuser={firstName:"Eric",lastName:"Liprandi",name:"Eric Liprandi",partner:"snapfish",username:"ericl"}; If it's not possible to directly get that from your other API, you can do: constuser={firstName:"Eric",lastName:"Liprandi",name:"Eric Liprandi",partner:"snapfish",passwordExpiration:undefined,username:"ericl"};if(user.passwordExpiration===undefined){deleteuser.passwordExpiration;} Given that in TypeScript But while testing this solution, it appeared that the current lib behavior is preventing another issue: in some scenarios, the lib is forced to fallback to So it means you would not get the exact same value when reading back (as Also, more generally, So I'm not sure yet how and even if we should fix/add this feature. It needs further thinking. |
BetaWas this translation helpful?Give feedback.
All reactions
👍 1
-
Merci pour la réponse et pour pour le package ;) |
BetaWas this translation helpful?Give feedback.
All reactions
❤️ 1