Skip to main content

Overview

Type generation automatically creates strongly-typed programming language interfaces from your SuprSend JSON schemas. Instead of manually writing type definitions, you define your workflow payload structure once as a JSON schema in SuprSend, and the CLI generates type-safe interfaces for TypeScript, Python, Go, Java, Kotlin, Swift, or Dart. This ensures payloads sent to workflows always match the expected schema, catching errors at compile time instead of at runtime.
Generated type files are auto-generated and should not be manually edited. Regenerate types when you update schemas in SuprSend.

Why Use Type Generation?

Without type generation, you work with plain objects that can lead to runtime errors. Type generation catches these errors during development with compile-time type safety and IDE autocomplete.
// ❌ Without types - bug may show up only at runtime
const data1 = { invoice_amount: "5000" };
const total1 = data1.invoice_amount + 500; // "5000500" (string concat)


// ✅ With generated types - error caught during development
type OrderCreatedEventData = {
  invoice_amount: number;
};
const data2: OrderCreatedEventData = { invoice_amount: "5000" };
//                         ^^^^^^^^^ TypeScript error:
// Type 'string' is not assignable to type 'number'.
You get early error detection, IDE autocomplete, immediate feedback when schemas change, and self-documenting code.

Generate Types

Prerequisites

Before generating types, ensure you have:
  1. SuprSend CLI installed
  2. Authenticated with your workspace
  3. ✅ Created and enabled schemas for your workflows (see guide)

Command Syntax

Once you’ve completed all the prerequisites, you can generate types using the following command in CLI. It will create type definitions for all the live schemas in your workspace:
suprsend generate-types <language> --output-file <output-file> [flags]
Here’s an example of how to generate types in all languages:
suprsend generate-types typescript
suprsend generate-types typescript --output-file types.ts

Supported Languages

LanguageFile ExtensionDefault Output File
TypeScript.tssuprsend-types.ts
Python.pysuprsend-types.py
Go.gosuprsend-types.go
Java.javasuprsend-types.java
Kotlin.ktsuprsend-types.kt
Swift.swiftsuprsend-types.swift
Dart.dartsuprsend-types.dart
For complete details on command arguments and flags, see the CLI Generate Types Reference.

Output File Structure

The output of the syntax generates a file with interfaces or definitions corresponding to all events and workflows that are linked to the schemas. So, there can’t be a mismatch between the schema mapped to the event or workflow while writing the code. All events are suffixed with Event keyword and workflows are suffixed with Workflow keyword.
from typing import Optional, List
from pydantic import BaseModel

class OrderCreatedEvent(BaseModel):
    order_id: str
    user_id: str
    order_amount: float
    currency: str
    payment_status: str
    discount_code: Optional[str] = None
    items_count: int

class SendInvoiceWorkflow(BaseModel):
    invoice_id: str
    invoice_amount: float
    invoice_date: str
    invoice_status: str
    invoice_due_date: str
    invoice_currency: str
    invoice_items: List[InvoiceItem]

Use Generated Types

Once generated, you can import the type definitions in your workflow or event triggers to ensure type safety throughout your codebase.
import { Suprsend, WorkflowTriggerRequest } from "@suprsend/node-sdk";
//Import the generated types
import { SendInvoiceWorkflow, OrderCreatedEvent } from "./suprsend-types";

const client = new Suprsend("workspace_key", "workspace_secret");

// ✅ Type-safe data creation
const triggerData: SendInvoiceWorkflow = {
   order_id: "Order-1234",
   user_id: "User-1234",
   order_amount: 5000,
   currency: "USD"
};

const body = {
   workflow: "send-invoice",
   recipients: [
       {
           distinct_id: "0gxxx9f14-xxxx-23c5-1902-xxxcb6912ab09",
           $email: ["[email protected]"],
           name: "recipient_1",
       },
   ],
   data: triggerData, // ✅ Type-safe
};

const wf = new WorkflowTriggerRequest(body, {
   tenant_id: "tenant_id",
   idempotency_key: "_unique_request_identifier",
});

const response = await client.workflows.trigger(wf);
console.log("response", response);
With Pydantic models (Python), you get runtime validation. Invalid data types will raise validation errors with clear messages.

Best Practices

  • Don’t edit generated files — treat them as build artifacts and regenerate from schema changes.
  • Regenerate on schema updates — keep types in sync with SuprSend schemas (ideally in the same PR as schema changes).
  • Automate in CI/CD — run type generation in your pipeline and fail the build if generated output is out of date.
  • Version your schemas — evolve payloads safely without breaking existing producers/consumers.
  • Use types at boundaries — type the payload right before calling workflows.trigger(...) (and validate incoming webhook/event payloads).

Frequently Asked Questions

If generated types don’t match your current schemas, regenerate them using the CLI:
suprsend generate-types typescript --output-file types.ts
Always regenerate types after updating or committing schemas in SuprSend.
This usually happens when:
  • The schema is still in draft and not committed
  • Types were not regenerated after schema changes
Ensure the schema is committed and regenerate the types using the CLI.
This typically means:
  • Generated types are outdated
  • The schema was changed in SuprSend but types weren’t regenerated
  • You’re generating types from the wrong workspace
Regenerate types and verify the --workspace flag if used.
Without type safety:
  • Errors surface only at runtime
  • Invalid payloads may partially process
  • Workflow conditions and templates can break silently
  • Debugging becomes harder across environments
No. Generated files should not be edited manually. Any changes will be overwritten the next time types are regenerated. Always update schemas in SuprSend and regenerate types.
You should regenerate types whenever:
  • A schema is added or updated
  • A field is added, removed, or renamed
  • A field’s datatype changes
Many teams automate this in CI/CD.
Yes. It’s recommended to add type generation to your CI/CD pipeline to ensure schemas and application code stay in sync across environments.
Type safety ensures that the data you send when triggering workflows or events strictly matches the schema defined in SuprSend. This helps catch missing fields, wrong data types, or invalid payloads during development instead of at runtime.
Type-safe triggers help prevent production bugs caused by incorrect payloads, improve developer experience with autocomplete and validation, and ensure your workflow logic always receives valid and expected data.
SuprSend generates strongly typed interfaces directly from your JSON schemas. You define the schema once in SuprSend, and the CLI generates language-specific types (TypeScript, Python, Go, Java, Kotlin, Swift, Dart) that stay in sync with your workflows.
SuprSend supports type generation for:
  • TypeScript
  • Python
  • Go
  • Java
  • Kotlin
  • Swift
  • Dart