{
base: { version: "v1" }, // may be "v2", etc
en: { /* 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:
How to create schema for this object?
I've found https://github.com/ianstormtaylor/superstruct/issues/1162#issuecomment-1860205487, https://github.com/ianstormtaylor/superstruct/issues/480#issuecomment-733274941:
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:s.object({ base: object({ version: enum(["v1", "v2"]) }), ...langsSchema, });