createEventSchema
createEventSchema<
TType,TDataObject>(type,dataObjectSchema):ZodObject<{data:ZodObject<{object:TDataObject; },$strip>;id:ZodString;type:ZodLiteral<TType>; },$strip>
Defined in: zod/src/index.ts:40
Create a typed event schema with a specific event type and data object schema
Type Parameters
Section titled “Type Parameters”TType extends string
TDataObject
Section titled “TDataObject”TDataObject extends ZodType<unknown, unknown, $ZodTypeInternals<unknown, unknown>>
Parameters
Section titled “Parameters”TType
The event type string (e.g., ‘issue.opened’)
dataObjectSchema
Section titled “dataObjectSchema”TDataObject
Zod schema for the data.object property
Returns
Section titled “Returns”ZodObject<{ data: ZodObject<{ object: TDataObject; }, $strip>; id: ZodString; type: ZodLiteral<TType>; }, $strip>
A Zod schema for the complete event
Example
Section titled “Example”const issueOpenedSchema = createEventSchema('issue.opened', z.object({ id: z.number(), title: z.string(), body: z.string().optional(),}));
type IssueOpenedEvent = z.infer<typeof issueOpenedSchema>;