I want to have an object like this:
{
a1: {
b1: {
c1: {
d1: 'foo',
d2: {
e1: 'bar'
},
d3: 'baz'
},
c2: 'hello'
},
b2: 'world',
b3: {
c1: {
d1: 'another',
d2: 'nested',
}
}
},
a2: 'thing'
}
Basically, the value associated with any key can be either a string
or Record<string, recurse>
... How can I accomplish this in TypeScript?
My attempt was:
type NestedRecordStringType = Record<string, RecordOrStringType>
type RecordOrStringType = string | Record<string, RecordOrStringType>
But it results in:
Type alias 'RecordOrStringType' circularly references itself.ts(2456)
How do I accomplish this sort of thing? I would then create a map:
const map: MyType = {
a1: {
b1: {
c1: {
d1: 'foo',
...
}
}
}
}
It must be something obvious I am missing.