I am seeking a way to restrict an object to only contain keys that adhere to a specific pattern. The pattern I require is: "{integer}a+{integer}c". An example of how it would be structured is as follows:
{
"2a+1c": {
// ...
}
}
Is there a method to guarantee that any new key added to this object complies with the defined pattern, without explicitly listing out all possible valid keys (as this is unfeasible)?
To provide further clarification on what I have in mind, here is an approach to ensuring an object only contains keys from an enum:
type ObjectWithEnumedKeys = {
[key in TheEnum]?: number;
}
It's important to note that I am not interested in solutions involving logic such as methods within a class or closures to enforce these restrictions.