Ensuring Type Safety with `Record.mapEntries` in TypeScript

Is there a way to have "tighter" types output from Record.mapEntries?
I'd like my greenVariants object to be of type GreenColorVariant, but .mapEntries "mixes" the record keys/values 😦

import { pipe } from "effect/Function"
import * as Record from "effect/Record"

const greens = {
  "green.50": "#eafff6",
  "green.100": "#cdfee8",
  "green.200": "#a0fad6",
  "green.300": "#63f2c1",
  "green.400": "#26e1a7",
  "green.500": "#01c38d",
  "green.600": "#00a377",
  "green.700": "#008262",
  "green.800": "#00674e",
  "green.900": "#005442",
  "green.950": "#003027"
} as const

type GreenColorVariant = {
  [P in keyof typeof greens]: [P, { backgroundColor: (typeof greens)[P] }]
}

const greenVariants = pipe(
  greens,
  Record.mapEntries((value, key) => [key, { backgroundColor: value }])
) satisfies GreenColorVariant

playground link: https://effect.website/play#f3903d48bfa4
Was this page helpful?