You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It's been a while since you asked this question, but perhaps the answer might still be useful for you or others.
You should be able to achieve what you ask for with the existing features of superstruct:
// Just like in TS where you can describe your desired behaviour with an intersection of a// type and a record:typeAddresses={requiredAddressField: string}&Record<string,string>// ...in Superstruct, you can do the same thing:constaddresses=intersection([type({requiredAddressField: string()}),record(string(),string()),]);
Note that it is important that you use type not object in this case, as object would not allow extraneous keys and validation would therefore not pass.
I will close this issue for now, but if there are some additional details you would like to discuss, feel free to comment!
First of all, thank you for this convenient tree-shakeable lib!
Sometimes we don't need to know, what the keys are in our object, but only their types
E.g. We keep addresses, added by user in structure like that:
TS allows us to do it
What if to add similar behavior in object structure, using a
Symbol
for that.Symbol
lets you distinguish this props from any others:The text was updated successfully, but these errors were encountered: