Today we're releasing support for workflow type generation through the CLI, making it easy to get end-to-end type safety between your application and the workflows you trigger with Knock.
Getting started with generating types is incredibly easy. You first describe your workflow trigger schema (or generate it using AI), then you can pull workflow type definitions from the Knock CLI:
knock workflow generate-types --output-file=./knock-workflow-types.ts
Next, within your application, you can import your types and annotate your Knock workflow triggers:
import { Knock } from "@knocklabs/node";
import { CommentCreatedData } from "./knock-workflow-types";
const knock = new Knock({ apiKey: process.env.KNOCK_API_KEY });
const triggerData: CommentCreatedData = {
comment_id: "comment_123",
comment_text: "Great work on this!",
document_id: "doc_456",
document_name: "Project Proposal",
priority: "medium",
metadata: {
source: "web_app",
version: 1,
},
};
await knock.workflows.trigger("comment-created", {
recipients: ["user_789"],
data: triggerData, // โ
Type-safe!
});
Your application's compilation will now fail if required data is missing or invalid data types are passed. This ensures that the data your workflow expects is provided.
The Knock CLI currently supports generating types for TypeScript, Go, Python, and Ruby. We may add other languages in the future. Please get in touch if there's a language you need that we don't currently support.
You can learn more in our guide on type safety and in the CLI documentation.
Other CLI improvements
We've also added support for two new commands in the Knock CLI:
knock pull
: Pulls down all versionable resources from your Knock account into the specified directory. Using this command, all resources will be pulled under their own directories (likeworkflows
,layouts
,partials
).knock push
: Pushes all resources in your Knock directory up to Knock in a single command, where you can optionally supply a commit message to pass along to commit and push at the same time.
Fixes and improvements
- ๐ [Dashboard] We fixed an issue where the discard changes button for setting trigger data did not always work
- ๐ [Dashboard] We fixed an issue where opening an email preview could have marked a message as "opened" inadvertently
- ๐ [Dashboard] We improved the categories filter on workflows to be a typeahead
- ๐ [Notification engine] We added support for a new
format_date_in_locale
liquid helper - ๐ [API] We fixed an issue with our OpenAPI spec where the set tenant endpoint listed that it accepted
preferences
- ๐ [SDK] We fixed an issue in the React SDK where the
useNotifications
hook could cause a memory leak - ๐ [Agent toolkit] We fixed an issue where some models would report issues with the tools provided by the MCP server
- ๐ [Agent toolkit] We added support for updating as well as creating workflow steps
- ๐ [Agent toolkit] We added support for upserting email layouts