workerd icon indicating copy to clipboard operation
workerd copied to clipboard

Add Workflow Types to workers-types

Open AbhiPrasad opened this issue 8 months ago • 8 comments

ref https://github.com/getsentry/sentry-javascript/pull/16704

The following types:

WorkflowEntrypoint,
WorkflowEvent,
WorkflowSleepDuration,
WorkflowStep,
WorkflowStepConfig,
WorkflowStepEvent,
WorkflowTimeoutDuration,

are not available via @cloudflare/workers-types (tested with 4.20250620.0). The Sentry Cloudflare SDK needs them for our upcoming Cloudflare Workflows instrumentation. It would be great if they got exposed!

The Sentry SDK ended up vendoring them in, but this will cause problems as the types get updated.

AbhiPrasad avatar Jun 23 '25 20:06 AbhiPrasad

Hi, perhaps i'm misunderstanding you, but it looks like these types are available? https://github.com/cloudflare/workerd/blob/main/types/generated-snapshot/latest/index.d.ts#L7999 https://github.com/cloudflare/workerd/blob/main/types/generated-snapshot/latest/index.d.ts#L7969 etc.

(these snapshots match what is published as workers-types)

emily-shen avatar Jul 28 '25 13:07 emily-shen

I apologize if I'm misunderstanding something, but when I tried to import this from the package I couldn't access WorkflowStep: https://stackblitz.com/edit/vitejs-vite-lobp6cn4?file=src%2Fmain.ts

Image

AbhiPrasad avatar Jul 28 '25 19:07 AbhiPrasad

So WorkflowStep is actually a native abstract class exported from workerd. It's available by importing from "cloudflare:workers". To ensure that "virtual module" is available in your code you need to add @cloudflare/workers-types to the tsconfig.

So to in your code you can use:

import type { WorkflowStep } from "cloudflare:workers";

let x: WorkflowStep;

and in your tsconfig.json you need:

{
	"compilerOptions": {
		// ...
		"types": [
			"@cloudflare/workers-types"
		]
	}
}

petebacondarwin avatar Aug 07 '25 16:08 petebacondarwin

I'm building a library that vendors in these types: https://github.com/getsentry/sentry-javascript/tree/develop/packages/cloudflare

importing from cloudflare:workers is breaking some user setups (https://github.com/getsentry/sentry-javascript/issues/16099) so I'm trying to move off of that to explicitly always import from @cloudflare/workers-types.

I would much prefer if we can avoid the virtual module for cloudflare library development.

AbhiPrasad avatar Aug 07 '25 16:08 AbhiPrasad

Hi. Are you able to share exactly what the issue is that this causes so that we can see if there's some way we could fix? As some of these types are classes used at runtime, they need to be importable from cloudflare:workers.

jamesopstad avatar Sep 01 '25 13:09 jamesopstad

https://github.com/getsentry/sentry-javascript/issues/16099 is the tracking issue for this problem, there are also multiple reproductions provided there.

As some of these types are classes used at runtime

Ideally I want full type safety for a method like https://github.com/getsentry/sentry-javascript/blob/12528ec04ce752db6e800f2d577c3d7fcda3d24b/packages/cloudflare/src/workflows.ts#L171

I want to make sure that users pass the right arguments to the wrapping function, and that the wrapping function returns the right value back.

AbhiPrasad avatar Sep 02 '25 14:09 AbhiPrasad

is this missing the awaiting Cloudflare response label?

sebws avatar Nov 08 '25 18:11 sebws

cc @jamesopstad @petebacondarwin

anonrig avatar Nov 08 '25 19:11 anonrig