bug: typescript error following batch.trigger example
Closed this issue · 1 comments
j-fdion commented
Provide environment information
System:
OS: Windows 11 10.0.26100
CPU: (24) x64 AMD Ryzen 9 5900X 12-Core Processor
Memory: 5.77 GB / 31.89 GB
Binaries:
Node: 24.1.0 - ~\AppData\Local\fnm_multishells\60100_1756134454396\node.EXE
npm: 11.3.0 - ~\AppData\Local\fnm_multishells\60100_1756134454396\npm.CMD
pnpm: 10.14.0 - ~\AppData\Local\fnm_multishells\60100_1756134454396\pnpm.CMD
bun: 1.2.1 - ~.bun\bin\bun.EXE
Describe the bug
tsc is telling me there's an error with my types, it was working properly in v3. Since v4 this doesn't work.
Tasks are defined like this:
import { logger, retry, schedules, tags, task, wait } from "@trigger.dev/sdk";
export const sendAttendanceSheetToEnterprise = task({
id: "send-attendance-sheet-to-enterprise-task",
run: async (
payload: { eventId: number; groupId: number; force?: boolean },
{ ctx: { environment } },
) {...}
I'm calling batch.trigger like this:
import type {
sendAttendanceSheetToCognibox,
sendAttendanceSheetToEnterprise,
} from "@acme/trigger/attendance-sheet";
const handle = await batch.trigger<
| typeof sendAttendanceSheetToCognibox
| typeof sendAttendanceSheetToEnterprise
>([
{
id: "send-attendance-sheet-to-cognibox-task",
payload: { eventId, groupId, force },
},
...groups.map((g) => {
return {
id: "send-attendance-sheet-to-enterprise-task" as const,
payload: { eventId: eventId, groupId: g.id, force },
};
}),
]);
error TS2344: Type 'Task<"send-attendance-sheet-to-enterprise-task", { eventId: number; groupId: number; force?: boolean | undefined; }, void> | Task<"send-attendance-sheet-to-cognibox-task", { ...; }, void>' does not satisfy the constraint 'Task<string, any, any>'.
Type 'Task<"send-attendance-sheet-to-enterprise-task", { eventId: number; groupId: number; force?: boolean | undefined; }, void>' is not assignable to type 'Task<string, any, any>'.
The types returned by 'trigger(...)' are incompatible between these types.
Type 'Promise<RunHandle<"send-attendance-sheet-to-enterprise-task", { eventId: number; groupId: number; force?: boolean | undefined; }, void>>' is not assignable to type 'Promise<RunHandle<string, any, any>>'.
Type 'RunHandle<"send-attendance-sheet-to-enterprise-task", { eventId: number; groupId: number; force?: boolean | undefined; }, void>' is not assignable to type 'RunHandle<string, any, any>'.
Type 'RunHandle<"send-attendance-sheet-to-enterprise-task", { eventId: number; groupId: number; force?: boolean | undefined; }, void>' is missing the following properties from type 'BrandRun<any, any>': [__output], [__payload]
1100 | typeof sendAttendanceSheetToCognibox
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1101 | typeof sendAttendanceSheetToEnterprise
Reproduction repo
https://trigger.dev/docs/triggering#batch-trigger
To reproduce
Follow the example from the doc.
Additional information
No response