-
Notifications
You must be signed in to change notification settings - Fork 1k
feat(type-generation): improve type generation for workflow #9705
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(type-generation): improve type generation for workflow #9705
Conversation
🦋 Changeset detectedLatest commit: 615ca52 The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
9ec6d5b to
696c853
Compare
create-cloudflare
@cloudflare/kv-asset-handler
miniflare
@cloudflare/pages-shared
@cloudflare/unenv-preset
@cloudflare/vite-plugin
@cloudflare/vitest-pool-workers
@cloudflare/workers-editor-shared
wrangler
commit: |
696c853 to
75d976e
Compare
|
@sidharthachatterjee could you take a look at this? |
|
Thanks @penalosa @LuisDuarte1 from the Workflows team will be reviewing this, cheers |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While the current approach technically works, I would prefer your latter approach with GetWorkflowPayload that uses the infer param instead of introspecting the type of payload field, wdyt?
|
@LuisDuarte1 Got it. Just one more thing, since we have no access to |
75d976e to
4df60c5
Compare
4df60c5 to
d737e5f
Compare
|
@LuisDuarte1 @penalosa just recently started using workflows and this PR would be a nice improvement. |
|
Well, if |
|
@penalosa can we get this in (after rebase)? |
|
@LuisDuarte1 are there concerns with the approach here? |
Would prefer to somehow hide the |
|
@hiendv in order to add the type helper, you'd have to make a PR to workerd modifying the workflows type definitions: https://github.com/cloudflare/workerd/blob/main/types/defines/workflows.d.ts. I'd be happy to review and get that released if you open one! |
|
OK so I took a look at workerd and it seems more complicated than anticipated.
// After export abstract class WorkflowEntrypoint
type AnyWorkflowEntrypoint = new (...args: any) => WorkflowEntrypoint;
export type WorkflowPayload<T extends AnyWorkflowEntrypoint> = InstanceType<T> extends WorkflowEntrypoint<unknown, infer P> ? P : never;
interface Env {
MY_WORKFLOW: Workflow<import('cloudflare:workers').WorkflowPayload<typeof import("./src/index").MyWorkflow>>;
}Doesn't seem better because of the |
d737e5f to
d318690
Compare
Lol, pipeline looks messy as well 😆 import("cloudflare:pipelines").Pipeline<import("cloudflare:pipelines").PipelineRecord>; |
d318690 to
615ca52
Compare
|
Congratulations @hiendv, the maintainer of this repository has issued you a holobyte! Here it is: https://holopin.io/holobyte/cmgs02iqy00c4l504gr4ixtz4 This badge can only be claimed by you, so make sure that your GitHub account is linked to your Holopin account. You can manage those preferences here: https://holopin.io/account. |
Fixes #9436
Make Workflow type generation stricter with
generateImportSpecifier(thanks to @ottomated #6259).Before:
After:
This type-hint looks a bit messy because params is only reflected with the run function. I think we could improve that by introducing a utility type (for now, I keep it simple with the "verbose" version).
And then: