Skip to content

In v4, task lifecycle hooks break types with "Types of parameters 'payload' and 'payload' are incompatible" error #2188

Open
@ericallam

Description

@ericallam

When using the barebones task function to define a task, and specifying the type of the payload parameter to the run function using a type definition, defining any of the lifecycle hooks before the run function leads to a type error. For example, this works fine:

export const exampleTask = task({
  id: "example-task",
  run: async (payload: { foobar: string }) => {
    console.log("Hello, world from the run function", { payload });
  },
  onStart: async ({ payload }) => {
    console.log(`payload.foobar: ${payload.foobar}`);
  },
});

Adding the 2nd argument to the run function breaks types:

Image

But only when the lifecycle hook is above the run function. Moving it below fixes the types:

export const exampleTask = task({
  id: "example-task",
  run: async (payload: { foobar: string }, { ctx }) => {
    console.log("Hello, world from the run function", { payload });
  },
  onStart: async ({ payload }) => {
    console.log(`payload.foobar: ${payload.foobar}`);
  },
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions