I've got the following function:
function merge<A extends Record<string, any>, K extends keyof A>(a: A): A[K] {
let ret = {} as A[K];
Object.keys(a).map((key) => {
ret = { ...ret, ...a[key] };
});
return ret;
}
const o = { en: { a: 1 }, de: { b: 2, c: "3" } };
const r = merge(o);
// r is of type {a:1} | {b:2,c:3}
// how do it turn it into: {a:1} & {b:2,c:3}?
The background of this function is basically merging locales together. So the real object would have as root keys something like "en", "de", "fr". And then a default locale is specified and if a key is missing on the default locale it is filled in from another locale.