Making Record Keys Optional and Using Transforms in Effect Typescript

Given the following schema
const Status = S.Literal("Ready", "InProgress")
const foo = S.Struct({
   statusOverrides: S.optional(S.Record({ key: Status, value: S.String })),
})


Is it possible to make the key's of type Status optional?

I'd like to be able to optionally override a status but not always be forced to override all here.

---

Follow up: Is it possible to use TaggedClasses's with transforms as record keys 🤔 (I couldn't find a way to do that)

const Status =  S.transform(
  S.Literal("Ready", "InProgress")
  S.Union(
    Ready,
    InProgress,
  ),
  {
    strict: true,
    decode: (literal) => ({
      "Ready": new Ready(),
      "InProgress": new InProgress(),
    })[literal],
    encode: (status) => ({
      Ready: "Ready",
      InProgress: "InProgress",
    } as const)[status._tag]
  }
);
Was this page helpful?