Go: How do I register a generic type method as workflow definition

Using Go SDK I’m trying to register a workflow definition which is implemented inside a type’s method but when I try to run it it fails with the following error:

"msg": "Failed to process workflow task.",
"Error": "unable to find workflow type: func1. Supported types: [MyWorkflowDef]"

This is what I do (partial code to fit question):

type MyType[T any] struct {
	Data T
}

func (lw *MyType[T]) MyWorkflowDef(wfctx workflow.Context) error {
	fmt.Println(lw.Data)
	return nil
}
var myWorkflow MyType[string] = MyType[string]{Data: "hello temporal"}

func codeThatRunsInGoroutine() {
    w := worker.New(client, workflowsTaskQueue, worker.Options{MaxConcurrentActivityExecutionSize:1})
    w.RegisterWorkflow(myWorkflow.MyWorkflowDef)
    w.Run(nil)
}

func TryingToRunWorkflow(ctx context.Context) {
	client.SignalWithStartWorkflow(ctx, "My Workflow", "My Signal", signal, workflowOptions, myWorkflow.MyWorkflowDef)
}

Technically this is a problem in 1.19 that was improved by the Go team in 1.20, but there are other problems with workflow definitions as generic methods (see here for a couple of the problems). We will probably be disallowing them soon.

You should use a non-generic function for a workflow, even if that means wrapping a generic function. Arguments and entry point should be clear for workflow callers. Also you should consider a top-level function instead of a method. Methods referencing external state can often lead to unexpected non-deterministic execution when said external state is modified or just different on another worker. Also top-level functions are clearer for callers.