@@ -119,17 +119,49 @@ export type EventDefinitionId<T extends AnyEventDefinition> =
119119
120120// ---- Implementation ----
121121
122- // Overload: with schema — payload type is inferred from schema
122+ /**
123+ * Define a typed event that can be published and subscribed to.
124+ *
125+ * When a schema is provided, the payload type is inferred from it and
126+ * validated at both publish time (SDK-side) and server-side (JSON Schema).
127+ *
128+ * @example
129+ * ```ts
130+ * import { event } from "@trigger.dev/sdk";
131+ * import { z } from "zod";
132+ *
133+ * // With schema — payload is typed as { orderId: string, amount: number }
134+ * export const orderCreated = event({
135+ * id: "order.created",
136+ * schema: z.object({ orderId: z.string(), amount: z.number() }),
137+ * });
138+ *
139+ * // Without schema — payload is `unknown`
140+ * export const systemAlert = event({ id: "system.alert" });
141+ *
142+ * // Publish
143+ * await orderCreated.publish({ orderId: "123", amount: 500 });
144+ *
145+ * // Subscribe
146+ * export const handler = task({
147+ * id: "handle-order",
148+ * on: orderCreated,
149+ * run: async (payload) => { // payload is typed
150+ * console.log(payload.orderId);
151+ * },
152+ * });
153+ * ```
154+ */
123155export function createEvent < TId extends string , TSchema extends Schema > (
124156 options : EventOptions < TId , TSchema > & { schema : TSchema }
125157) : EventDefinition < TId , inferSchemaIn < TSchema > > ;
126158
127- // Overload: without schema — payload type is unknown
159+ /** @see { @link createEvent } */
128160export function createEvent < TId extends string > (
129161 options : EventOptions < TId , undefined >
130162) : EventDefinition < TId , unknown > ;
131163
132- // Overload: without schema (no schema field at all)
164+ /** @see { @link createEvent } */
133165export function createEvent < TId extends string > (
134166 options : Omit < EventOptions < TId > , "schema" >
135167) : EventDefinition < TId , unknown > ;
@@ -277,7 +309,12 @@ export function createEvent<TId extends string, TSchema extends Schema | undefin
277309 return eventDef ;
278310}
279311
280- /** The public `event()` function for defining events */
312+ /**
313+ * Define a typed event that can be published and subscribed to.
314+ * Alias for {@link createEvent}.
315+ *
316+ * @see {@link createEvent } for full documentation and examples.
317+ */
281318export const event = createEvent ;
282319
283320/** Check if a value is an EventDefinition */
0 commit comments