sdk-typescript
sdk-typescript copied to clipboard
[Bug] Inconsistent Type Definition of Workflow Arguments
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.
Can you please clarify in which case this is posing problems?
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>)