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
{base: {version: "v1"},// may be "v2", etcen: {/* lang constant */},ge: {/* lang constant */},fr: {/* lang constant */},/* ... long list of languages ... */}
intersection([type({version: enum(["v1","v2"])}),record(string()/* <-- should be enums(["en", ... ]) */,LangConstant)])
But the problem is, as stated in the comment, that I lose list of remaining keys of the object. And even if I use enums() instead of string() as key, the schema wont validate properly (because of missing base key or wrong value type below base). So there are options:
Add all languages in a object schema:
s.object({base: object({version: enum(["v1","v2"])}),en: LangConstant,ge: LangConstant,/* ...other languages */});
Add helpers:
constlanguages=["en","ge",/* ...other languages */];constlangsSchema=langs.reduce((acc,lang)=>{return{ ...acc,[lang]: LangConstant};},{});s.object({base: object({version: enum(["v1","v2"])}),
...langsSchema,});
But the first one have a lot of repetition, and second have a separation from superstruct.
Is there a more concise way to specify such schema?
The text was updated successfully, but these errors were encountered:
How to create schema for this object?
I've found #1162 (comment), #480 (comment):
But the problem is, as stated in the comment, that I lose list of remaining keys of the object. And even if I use
enums()
instead ofstring()
as key, the schema wont validate properly (because of missingbase
key or wrong value type belowbase
). So there are options:But the first one have a lot of repetition, and second have a separation from
superstruct
.Is there a more concise way to specify such schema?
The text was updated successfully, but these errors were encountered: