fix(): workflow sdk step return function type infer (#7047)
This commit is contained in:
@@ -4,12 +4,10 @@ const step1 = createStep("step1", async (input: {}, context) => {
|
|||||||
return new StepResponse({ step1: ["step1"] })
|
return new StepResponse({ step1: ["step1"] })
|
||||||
})
|
})
|
||||||
|
|
||||||
const step2 = createStep(
|
type Step2Input = { filters: { id: string[] } } | { filters: { id: string } }
|
||||||
"step2",
|
const step2 = createStep("step2", async (input: Step2Input, context) => {
|
||||||
async (input: { filters: { id: string[] } }, context) => {
|
return new StepResponse({ step2: input })
|
||||||
return new StepResponse({ step2: input })
|
})
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
const step3 = createStep("step3", async () => {
|
const step3 = createStep("step3", async () => {
|
||||||
return new StepResponse({ step3: "step3" })
|
return new StepResponse({ step3: "step3" })
|
||||||
@@ -21,7 +19,14 @@ const workflow = createWorkflow("workflow", function () {
|
|||||||
return step2({ filters: { id: step1Res.step1 } })
|
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({})
|
.run({})
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
console.log(res.result)
|
console.log(res.result)
|
||||||
|
|||||||
@@ -25,7 +25,10 @@ type StepFunctionReturnConfig<TOutput> = {
|
|||||||
* @typeParam TInput - The type of the input of the step.
|
* @typeParam TInput - The type of the input of the step.
|
||||||
* @typeParam TOutput - The type of the output 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
|
? // Function that doesn't expect any input
|
||||||
{
|
{
|
||||||
(): WorkflowData<TOutput> & StepFunctionReturnConfig<TOutput>
|
(): WorkflowData<TOutput> & StepFunctionReturnConfig<TOutput>
|
||||||
|
|||||||
Reference in New Issue
Block a user