Skip to content

Commit 96be791

Browse files
fix(workflow): make ExternalWorkflowHandle.signal signature match that of BaseWorkflowHandle.signal (#1237)
Co-authored-by: Gabriel Santos-Blanchet <gsantosblanchet@progymedia.com>
1 parent a2007ac commit 96be791

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

packages/test/src/test-interface-type-safety.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import test from 'ava';
2-
import { defineSignal, defineQuery } from '@temporalio/workflow';
2+
import { defineSignal, defineQuery, ExternalWorkflowHandle, ChildWorkflowHandle, Workflow } from '@temporalio/workflow';
3+
import { WorkflowHandle } from '@temporalio/client';
34

45
test('SignalDefinition Name type safety', (t) => {
56
// @ts-expect-error Assert expect a type error when generic and concrete names do not match
@@ -53,3 +54,15 @@ test('QueryDefinition Args and Ret type safety', (t) => {
5354
const _argAssertion: ArgTypeAssertion = 'not-intermixable';
5455
t.pass();
5556
});
57+
58+
test('Can call signal on any WorkflowHandle', async (t) => {
59+
// This function definition is an assertion by itself. TSC will throw a compile time error if
60+
// the signature of the signal function is not compatible across all WorkflowHandle variants.
61+
async function _assertion<T extends Workflow>(
62+
handle: WorkflowHandle<T> | ChildWorkflowHandle<T> | ExternalWorkflowHandle
63+
) {
64+
await handle.signal(defineSignal('signal'));
65+
}
66+
67+
t.pass();
68+
});

packages/workflow/src/workflow-handle.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ export interface ExternalWorkflowHandle {
1717
* await handle.signal(incrementSignal, 3);
1818
* ```
1919
*/
20-
signal<Args extends any[] = []>(def: SignalDefinition<Args> | string, ...args: Args): Promise<void>;
20+
signal<Args extends any[] = [], Name extends string = string>(
21+
def: SignalDefinition<Args, Name> | string,
22+
...args: Args
23+
): Promise<void>;
2124

2225
/**
2326
* Cancel the external Workflow execution.

0 commit comments

Comments
 (0)