I have a nested object that I want to flatten whilst also concatenating the nested keys. I want to go from this:
const nested = {
a: {
b: {
c: {
d1: "hello",
d2: 42,
},
},
},
};
To this:
const flattened = {
"a.b.c.d1": "hello",
"a.b.c.d2": 42,
};
If I have a function that performs this transform, e.g.
function flatten<TNested>(nested: TNested): Flattened<TNested> {...}
Is it possible to define the type Flattened
that does the right thing and correctly infers the type of flattened
?
I appreciate it might just not be possible with current TypeScript, but would like to know for sure!