Open
Description
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:
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
Labels
No labels