fix(): workflow sdk step return function type infer (#7047)

This commit is contained in:
Adrien de Peretti
2024-04-10 15:49:09 +02:00
committed by GitHub
parent ab7ff64c4a
commit eac4d2d87a
2 changed files with 16 additions and 8 deletions

View File

@@ -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)

View File

@@ -25,7 +25,10 @@ type StepFunctionReturnConfig<TOutput> = {
* @typeParam TInput - The type of the input of the step.
* @typeParam TOutput - The type of the output of the step.
*/
export type StepFunction<TInput, TOutput = unknown> = (keyof TInput extends []
export type StepFunction<
TInput,
TOutput = unknown
> = (keyof TInput extends never
? // Function that doesn't expect any input
{
(): WorkflowData<TOutput> & StepFunctionReturnConfig<TOutput>