bug: Typescript error when using `ctx` on the `run` function when using any lifecycle methods
Closed this issue · 3 comments
Provide environment information
System:
OS: macOS 15.6
CPU: (12) arm64 Apple M2 Pro
Memory: 145.56 MB / 32.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 22.14.0 - ~/.nvm/versions/node/v22.14.0/bin/node
npm: 10.9.2 - ~/.nvm/versions/node/v22.14.0/bin/npm
pnpm: 10.14.0 - ~/.nvm/versions/node/v22.14.0/bin/pnpm
bun: 1.1.21 - ~/.bun/bin/bun
Describe the bug
When using any of the lifecycle events (onStart, onFailure), and trying to use ctx in run function, Typescript errors with
TS2769: No overload matches this call.
Overload 1 of 2,
(params: TaskOptionsWithSchema<"test-task", void, any>): Task<"test-task", any, void>
and lifecycle payload becomes any
Removing ctx from run arguments fixes it
Reproduction repo
https://stackblitz.com/edit/stackblitz-starters-ljt2cevv?file=triggers%2Ftest-task.ts
To reproduce
import { queue, task } from '@trigger.dev/sdk';
async function findRequest({ id }: { id: string }) {
return new Promise((resolve) => setTimeout(resolve, 200));
}
export const testTask = task({
id: 'test-task',
retry: {
maxAttempts: 2,
},
machine: {
preset: 'medium-2x',
},
onStart: async ({ ctx: { task }, payload: { requestId } }) => {
console.log('debug', { task, requestId });
},
run: async (payload: { requestId: string; userPrompt?: string }, { ctx }) => {
//Remove `ctx` to fix the issue
const { requestId, userPrompt } = payload;
await findRequest({ id: requestId });
},
});
Run tsc to observe. Then remove ctx from run params and run tsc again
Additional information
"@trigger.dev/core": "4.0.0-v4-beta.27",
"@trigger.dev/sdk": "4.0.0-v4-beta.27",
This is a duplicate of #2188
Oh good to know that I can swap the order for now at least. Ty
This is a duplicate of #2188
Really good write-up and solution list there, perhaps there's a good place in docs where to add it? Maybe a new Typescript section in the docs