You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The choice to use Generators for Durable Functions in Azure was deliberate as I understand it, but it has made strongly typing the APIs for Orchestrations and Activities very challenging. With custom Promise implementations the typing is pretty straightforward, but the replay-ability is probably harder?
I don't think Typescript supports stronger typing of the types on a per-yield result basis (microsoft/TypeScript#32523). Is there a plan for this that will make this process way less painful? I'm usually pretty fantastic at hacking around stuff like this with typescript, but I can't figure out how in this scenario (specifically for activity return types).
Investigative information
Durable Functions extension version: ? Installed automagically by tooling. No clue. ?,
Language (JavaScript/TypeScript) and version: Typescript ^5.1.3
Node.js version: node v18.12.1
If deployed to Azure App Service
Local only at this time.
If you don't want to share your Function App name or Functions names on GitHub, please be sure to provide your Invocation ID, Timestamp, and Region - we can use this to look up your Function App/Function. Provide an invocation id per Function. See the Functions Host wiki for more details.
To Reproduce
Check out the ActivityCaller type below. VS Code complains (with good reason) that the Output parameter is unused:
importtype{FunctionInput,FunctionOutput,InvocationContext}from"@azure/functions";importtype{OrchestrationContext,ActivityHandler,RetryOptions}from"durable-functions";import{app}from"durable-functions";typeActivityExtraOptions=Partial<{extraInputs: FunctionInput[];extraOutputs: FunctionOutput[];}>;typeCallOptions=Partial<{retry: RetryOptions;}>;typeHandler<Input,Output>=(input: Input,ctx: InvocationContext)=>Promise<Output>;// LOOK HERE: I cannot type this in any meaningful way that results in a type I can manipulate into// const out: Output = yield callThisFunction(ctx, "input");typeActivityCaller<Input,Output>=(ctx: OrchestrationContext,input: Input,{ retry }?: CallOptions)=>Task;exportfunctioncreateActivity<Input,Output>(name: string,handler: Handler<Input,Output>): ActivityCaller<Input,Output>;exportfunctioncreateActivity<Input,Output>(name: string,options: ActivityExtraOptions,handler: Handler<Input,Output>): ActivityCaller<Input,Output>;exportfunctioncreateActivity<Input,Output>(name: string,handlerOrOptions: ActivityHandler|ActivityExtraOptions,maybeHandler?: ActivityHandler,): ActivityCaller<Input,Output>{letoptions=typeofhandlerOrOptions==="function" ? {} : handlerOrOptions;lethandler=typeofhandlerOrOptions==="function" ? handlerOrOptions : maybeHandler;if(handler==null){thrownewError("Options were passed, but no handler was passed?");}app.activity(name,{
...options,
handler,});returnObject.defineProperty(function(ctx: OrchestrationContext,input: Input,{ retry }: CallOptions={}){if(retry){returnctx.df.callActivityWithRetry(name,retry,input)asOutput;}else{returnctx.df.callActivity(name,input)asOutput;}},"name",{value: name});}
Expected behavior
There is some way other than as or type assertions in the orchestrator to bind the return type of a called function to the Task result type.
Actual behavior
There is not such a technique that I know of.
Screenshots
N/A
Known workarounds
as or manually specifying this stuff.
Additional context
N/A
The text was updated successfully, but these errors were encountered:
And in the calling orchestrator I can use them like so:
import{createActivityWithInput,typeYielded}from"../createActivity.js";import{createOrchestrator}from"../createOrchestrator.js";exportconstload=createActivityWithInput<number,string>("demo",async(input,ctx)=>{returninput.toString();});exportconstsync=createOrchestrator("sync-orchestrator",function*(ctx){ctx.log("Syncing");constx: Yielded<typeofload>=yieldload(ctx,10);ctx.log("Yielded "+JSON.stringify(x)+" as "+typeofx);});
It behaves as expected, it is still way less than ideal.
Describe the bug
The choice to use Generators for Durable Functions in Azure was deliberate as I understand it, but it has made strongly typing the APIs for Orchestrations and Activities very challenging. With custom Promise implementations the typing is pretty straightforward, but the replay-ability is probably harder?
I don't think Typescript supports stronger typing of the types on a per-yield result basis (microsoft/TypeScript#32523). Is there a plan for this that will make this process way less painful? I'm usually pretty fantastic at hacking around stuff like this with typescript, but I can't figure out how in this scenario (specifically for activity return types).
Investigative information
If deployed to Azure App Service
Local only at this time.
To Reproduce
Check out the
ActivityCaller
type below. VS Code complains (with good reason) that theOutput
parameter is unused:Expected behavior
There is some way other than
as
or type assertions in the orchestrator to bind the return type of a called function to the Task result type.Actual behavior
There is not such a technique that I know of.
Screenshots
N/A
Known workarounds
as
or manually specifying this stuff.Additional context
N/A
The text was updated successfully, but these errors were encountered: