We use cookies

We use cookies to ensure you get the best experience on our website. For more information on how we use cookies, please see our cookie policy.

By clicking "Accept", you agree to our use of cookies.
Learn more.

User GuideTypescript Migration Guide

Hatchet TypeScript V1 Migration Guide

This guide will help you migrate Hatchet workflows from the V0 SDK to the V1 SDK.

Introductory Example

First, we’ve exposed a new hatchet.task method in the V1 SDK for single-task workflows.

Dags are still defined as workflows, but they can now be declared using the hatchet.workflow method.

You can now run work for tasks and workflows by directly interacting with the returned object.

There are a few important things to note when migrating to the new SDK:

  1. The new SDK uses a factory pattern (shown above) for creating workflows and declaring their tasks, which we’ve found to be more ergonomic than the previous SDK.
  2. The old method of defining workflows will still work in the new SDK, but we recommend migrating over to the new method shown above for improved type checking and for access to new features.
  3. New features of the SDK, such as the new durable execution features rolled out in V1, will only be accessible from the new WorkflowDeclaration object in the new SDK.

Since the old pattern for declaring workflows will still work in the new SDK, we recommend migrating existing workflows to the new patterns in V1 gradually.

Fanout Example

The new SDK also provides improved type support for spawning workflows (such as children) from around the codebase. Consider the following example:

First, we declare a child workflow:

Next, we spawn that child from a parent workflow:

In this example, the compiler knows what to expect for the types of input and ctx for each of the tasks, as well as the type of the input of the child task when spawning it from the parent task.