Skip to content

Triggering from your app

Typed payloads

In TypeScript, pass the task's type to tasks.trigger. The compiler then checks the payload you send and types the output you read back.

On this page

Type a trigger from the task#

A Node task is an exported function: its first parameter is the payload, and what it returns is the output. Import its type, and pass it as the type argument:

tasks/email.ts
import type { Context } from '@bokjoy/sdk'; export interface Email {  email: string;  template: 'welcome' | 'nudge';} export async function send(payload: Email, ctx: Context) {  console.log(`send ${payload.template} (key ${ctx.idempotencyKey})`);  return { sent: true };}
app.ts
import { runs, tasks, type Task } from '@bokjoy/sdk';// Type only: the compiler checks against the task, and none of// its code is loaded into this app.import type { send } from './tasks/email.ts'; const handle = await tasks.trigger<typeof send>('email.send', {  email: 'ada@example.com',  template: 'welcome',}); // The handle remembers the task, so the run's output is typed.const run = await runs.poll(handle, { timeoutMs: 60_000 });const sent: boolean | undefined = run.output?.sent;console.log(run.status, sent); // Without the task's source, describe the task instead.type Report = Task<{ month: string }, { url: string }>;const { url } = await tasks.triggerAndWait<Report>(  'reports.build',  { month: '2026-09' },  { timeoutMs: 120_000 },);console.log(url);
  • tasks.trigger<typeof send> checks the payload against send's first parameter. A missing or misspelled field is a compile error.
  • The handle remembers the task, so runs.poll(handle) and runs.retrieve(handle) type output and payload too.
  • tasks.triggerAndWait<typeof send> returns the task's output type.
  • import type is erased by the compiler and by Node's type stripping, so none of the task's code, or its dependencies, loads into your app.

Node 24 runs .ts files as they are, with no build step. app.ts uses top-level await, so its package.json needs "type": "module". A task file can be .ts too: name it as the manifest's entrypoint.

Task files in TypeScript#

There are two ways to run a .ts task:

Without buildWith a build section
How it runsNode strips the types and runs the fileesbuild compiles it to .mjs at deploy
SyntaxOnly types Node can erase: no enum, no parameter propertiesAnything esbuild compiles, enum and JSX included
ImportsRelative, with the file extension, inside the task's folderAnywhere in the project, without extensions, with tsconfig paths and JSON
PackagesFrom dependencies, installed beside the codeBundled from the lock, or installed as external

Neither checks types. Run tsc --noEmit yourself, as you would before a Trigger.dev deploy.

Task objects#

A task defined the Trigger.dev way is typed by its object, as in Trigger.dev. Its trigger and batchTrigger check the payload against run's first parameter, and typeof the object works as the type argument:

app.ts
import { tasks } from '@bokjoy/sdk';import type { processOrder } from './src/trigger/orders'; const handle = await tasks.trigger<typeof processOrder>('orders.process', {  orderId: 'A1',  lines: [{ qty: 2, price: 350 }],});

Inside another task, processOrder.trigger({ ... }) needs no ID at all. A schemaTask takes the type its schema parses to, and a schedules.task gets Trigger.dev's scheduled payload, with Date fields.

Describe a task you cannot import#

When the task lives in another repository, describe it with Task<Payload, Output>:

TypeScript
import { tasks, type Task } from '@bokjoy/sdk'; type SendEmail = Task<  { email: string; template: 'welcome' | 'nudge' },  { sent: boolean }>; const { sent } = await tasks.triggerAndWait<SendEmail>('email.send', {  email: 'ada@example.com',  template: 'welcome',});

What the types cannot check#

  • The task ID. A manifest's IDs are not in the code, so 'email.send' is not checked against send. Keep the ID and the type next to each other, for example in one module your app imports. A task object carries its own ID: call its trigger from inside a run, and no ID is written at all.
  • The deployed code. The types describe the code you compiled against. If the deployment that runs is older or newer, the payload it accepts can differ.

Without a type argument, the payload is any JSON value and the output is JSONValue.