Merging and reducing const asserted objects and keeping narrow types

Suppose I have some const stuff:
const settings1 = {
  settings: { b: 1 },
  env: ["beta", "prod"],
} as const;
const settings2 = {
  settings: { x: 123 },
  env: ["prod", "specialenv"],
} as const;

And I want to merge all of those into:
{
  beta: {b: 1},
  prod: {b: 1, x: 123},
  specialenv: {x: 123},
}

Easy enough with some javascript array flatmap + reduce but can I do that with Effect's to produce the final object with narrow types (keeping the const asserted narrow types) so that I can actuall read the output from the types?
Was this page helpful?