Passing functions from activities to workflows

I have an activity that passes in a workflow fn in an object back to the workflow, and then the workflow is supposed to retrieve that workflow fn and use it as a child workflow.

workflow code looks smth like

const node = mainService.getNodeDetails()
await executeChild(node.workflow);
import { childWorkflow } from 'other-package';
const getNodeDefDetails = async() => {
  const nodeDetails = {
    name: 'testing'
    workflow: childWorkflow
  return nodeDetails;

So I put logging statement, and it seems that in the return statement of my activity, the object with the workflow is what’s returned by the activity.

  name: 'testing',
  workflow: [AsyncFunction: childWorkflow]

However, when I print out the variable node in my workflow (the result of the activity), it is now missing the workflow property. I now get

  name: 'testing',

Also verified in the Temporal webUI if this is what it thinks is being returned by the activity, and it matches that object without the workflow fn.
Is this expected behavior? Is there any constraints on what can’t be passed back to a workflow from an activity?

I’m not expert on Typescript SDK, but I believe function pointers are not serializable to JSON. The workaround is to pass workflow type name as a string. It is possible to create a child workflow by its string name only.

1 Like

Maxim is right, you cannot pass around functions in arguments and return values, you can send the function’s name ( though.
Any values passed around should be serializable using a data converter: Interface: DataConverter | Temporal Node.js SDK API Reference

Oof that totally makes sense. Will be passing in the name instead of the actual fn now, thank you!