I am seeking to define a type for an arbitrary object with only string
keys (excluding symbol
) at each level of nesting.
Here is what I envision (though the example provided does not work and is not valid):
type RecursiveRecord = {
[key: string]:
RecursiveRecord[key] extends object ?
RecursiveRecord : // nested object, apply same key restriction
RecursiveRecord[key], // non-object value
}
Is there a way to accomplish this goal effectively?
Many thanks.
P.S.
Perhaps my question can also be phrased as "How do I describe the type that is opposite of object
?". In that case, I could potentially write something like this:
type RecursiveRecord = { [key: string]: Not<object> | RecursiveRecord };
.