Skip to main content
Defines a typed hook for type-safe hook creation and resumption. This provides compile-time type safety and optional runtime validation using a schema.

Signature

Parameters

object
Configuration options for the typed hook.

Type Parameters

type
The type of the input payload when resuming the hook from external contexts.
type
default:"TInput"
The type of the output payload received in the workflow after validation/transformation.

Returns

TypedHook<TInput, TOutput>
An object with create and resume methods.

Usage

Basic Typed Hook

Define a hook with a specific payload type:

Hook with Schema Validation

Validate and transform input using Zod:

Hook with Transformation

Transform input data before it reaches the workflow:

Separate Input and Output Types

Use different types for input and output:

Extract Input Type

Use the TypedHook.Input helper:

Notes

  • The create() method can only be called inside a workflow function
  • The resume() method can only be called outside a workflow function (e.g., API routes)
  • If a schema is provided, validation errors will be thrown when calling resume()
  • Schemas must conform to the Standard Schema specification
  • Popular schema libraries like Zod, Yup, and Valibot are compatible