Porting Event Handlers to Effect: Inference for Handler Function Lost

Hello, trying to port event handlers in my project to effect. To create an event handler you need to pass 3 args. The cool thing is that createFunction infers a type for a handler based on the event name. I tried to create a type for a data structure that would describe an event handler. It worked but the inference for handler function is lost.

Is there a potential solution for this?

const handler = inngest.createFunction(
    { name: 'Update Financial History when Codat data changes' },
    { event: 'codat-adapter/dataset.changed' },
    async ({ event }) => {
        if (event.data.dataType == 'banking-accountBalances') {
            await financialHistoryService.handleDataChanged(event.data)
        }
    },
)

type CreateHandlerDescription<T extends (...args: any) => any> = T extends (
    nameOrOps: infer N,
    trigger: infer T,
    handler: infer H,
) => any
    ? {
          nameOrOps: N
          trigger: T
          handler: H
      }
    : never

type HandlerDescription = CreateHandlerDescription<typeof inngest.createFunction>

const handlerAsData: HandlerDescription = {
    nameOrOps: { name: 'Update Financial History when Codat data changes' },
    trigger: { event: 'codat-adapter/dataset.changed' },
    handler: async ({ event }) => {
        if (event.data.dataType == 'banking-accountBalances') {
            await financialHistoryService.handleDataChanged(event.data)
        }
    },
}
Was this page helpful?