diff --git a/packages/workflows-sdk/src/utils/_playground.ts b/packages/workflows-sdk/src/utils/_playground.ts index f2129c1973..57d2b05b09 100644 --- a/packages/workflows-sdk/src/utils/_playground.ts +++ b/packages/workflows-sdk/src/utils/_playground.ts @@ -4,12 +4,10 @@ const step1 = createStep("step1", async (input: {}, context) => { return new StepResponse({ step1: ["step1"] }) }) -const step2 = createStep( - "step2", - async (input: { filters: { id: string[] } }, context) => { - return new StepResponse({ step2: input }) - } -) +type Step2Input = { filters: { id: string[] } } | { filters: { id: string } } +const step2 = createStep("step2", async (input: Step2Input, context) => { + return new StepResponse({ step2: input }) +}) const step3 = createStep("step3", async () => { return new StepResponse({ step3: "step3" }) @@ -21,7 +19,14 @@ const workflow = createWorkflow("workflow", function () { return step2({ filters: { id: step1Res.step1 } }) }) -workflow() +const workflow2 = createWorkflow("workflow", function () { + const step1Res = step1() + step3() + workflow() + return step2({ filters: { id: step1Res.step1 } }) +}) + +workflow2() .run({}) .then((res) => { console.log(res.result) diff --git a/packages/workflows-sdk/src/utils/composer/type.ts b/packages/workflows-sdk/src/utils/composer/type.ts index 91f9e2b296..824527f34a 100644 --- a/packages/workflows-sdk/src/utils/composer/type.ts +++ b/packages/workflows-sdk/src/utils/composer/type.ts @@ -25,7 +25,10 @@ type StepFunctionReturnConfig = { * @typeParam TInput - The type of the input of the step. * @typeParam TOutput - The type of the output of the step. */ -export type StepFunction = (keyof TInput extends [] +export type StepFunction< + TInput, + TOutput = unknown +> = (keyof TInput extends never ? // Function that doesn't expect any input { (): WorkflowData & StepFunctionReturnConfig