Skip to content

Add typegen for workflow contexts to help using createWorkflow#153

Merged
bkegley merged 2 commits intomainfrom
bk/workflow-context-typegen
Apr 15, 2026
Merged

Add typegen for workflow contexts to help using createWorkflow#153
bkegley merged 2 commits intomainfrom
bk/workflow-context-typegen

Conversation

@bkegley
Copy link
Copy Markdown
Contributor

@bkegley bkegley commented Apr 15, 2026

Adds a generate-types CLI tool that fetches workflow context schemas to generate type declarations to improve the type-safety of using createWorkflow

Usage

prism login
npx @prismatic-io/embedded generate-types -o prismatic.d.ts

Then add the generated file to your tsconfig.json:

{
  "include": ["prismatic.d.ts"]
}

Review Peculiarities

  • export {} in generated output — required so TypeScript treats the file as a module augmentation rather than an ambient module declaration (which would replace the module's types entirely)
  • Stable key interface deduping — distinct stableKeys that produce the same PascalCase type name (e.g. my-workflow and myWorkflow both → MyWorkflowContext) get suffixed as MyWorkflowContext1, MyWorkflowContext2. This is all internal to the module augmentation so it doesn't matter.
  • Separate tsconfig for generatorstsconfig.generators.json compiles src/generators/ to CommonJS independently from the webpack build

CLI tool (`generate-types`) to generate types for WorkflowContexts
defined in a tenant for type safety when using `createWorkflow`
@bkegley bkegley force-pushed the bk/workflow-context-typegen branch from 74204b0 to f92ca4d Compare April 15, 2026 03:01
Comment thread src/generators/cli.ts Outdated

for (let i = 0; i < args.length; i++) {
if (args[i] === "--output" || args[i] === "-o") {
output = args[++i];
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be worth it to add proper argument checking here? In this case I could see checking that there is a next argument and it doesn't start with -, similar to how most of the other CLI parsing libraries handle it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's good feedback. Swapped to node's built-in.

@bkegley bkegley merged commit eb721af into main Apr 15, 2026
1 check passed
@bkegley bkegley deleted the bk/workflow-context-typegen branch April 15, 2026 16:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants