sdk-typescript icon indicating copy to clipboard operation
sdk-typescript copied to clipboard

[Bug] Inconsistent Type Definition of Workflow Arguments

Open hiramhuang opened this issue 1 year ago • 2 comments

What are you really trying to do?

I'm working on creating a reusable generic type that extends from the Workflow type.

Describe the bug

The type definition of arguments on the Workflow type is inconsistent with the condition expression on WithWorkflowArgs type. This inconsistency could become problematic when attempting to create a generic type that extends the Workflow type.

Minimal Reproduction

Not applicable.

Environment/Versions

Not applicable.

Additional context

Not applicable.

hiramhuang avatar Apr 08 '24 08:04 hiramhuang

Can you please clarify in which case this is posing problems?

mjameswh avatar Apr 10 '24 19:04 mjameswh

Can you please clarify in which case this is posing problems?

Due to any[] (on Workflow type) not being equal to [any, ...any[]] (on WithWorkflowArgs type), the following example function will not pass type checking. This is because it cannot satisfy WorkflowStartOptions<WT> when arguments are passed from Parameters<WT>:

const getWorkflowStartOptions = <WT extends Workflow>(...args: Parameters<WT>) => ({
  ...defaultOptions,
  ...args,
} satisfies WorkflowStartOptions<WT>)

It will work if we don't extend from the Workflow type. Instead, we define a version of Workflow type that is compatible with WithWorkflowArgs type:

const getWorkflowStartOptions = <WT extends (...args: [any, ...any[]]) => Promise<any>>(...args: Parameters<WT>) => ({
  ...defaultOptions,
  ...args,
} satisfies WorkflowStartOptions<WT>)

hiramhuang avatar Apr 11 '24 06:04 hiramhuang