Effect CommunityEC
Effect Communityβ€’2y agoβ€’
10 replies
attila

Streamlining Service Updates with a Helper Function in TypeScript

Has anyone else here found themselves doing the following over and over again:
Effect.updateService(MyTag, (service) => ({
  ...service,
  myStubbedField: stubbedField,
}))

and then come up with the following helper function?
const updateService = <T extends Context.Tag<any, any>>(
  tag: T,
  override: Partial<Context.Tag.Service<T>>,
) => Effect.updateService(tag, (service) => ({ ...service, ...override }))

With it, the above just becomes:
updateService(MyTag, { myStubbedField: stubbedField })


If it's not just me and would be generally useful to more of us, we could possibly upstream it to effect.
Was this page helpful?