Skip to content

Commit 1056824

Browse files
committed
Fix types
1 parent 2692ce1 commit 1056824

2 files changed

Lines changed: 29 additions & 12 deletions

File tree

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/sdk/worker/decorators/worker.ts

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -208,13 +208,17 @@ export interface WorkerOptions {
208208
* }
209209
* ```
210210
*/
211+
/** Minimal context shape for Stage 3 method decorators (TypeScript 5.0+). */
212+
interface MethodDecoratorContext {
213+
kind: string;
214+
name: string | symbol;
215+
}
216+
211217
/**
212218
* Type guard for Stage 3 (TypeScript 5.0+) decorator context.
213219
* New decorators pass (value, context) where context has a `kind` property.
214220
*/
215-
function isNewDecoratorContext(
216-
arg: unknown
217-
): arg is { kind: string; name: string | symbol } {
221+
function isNewDecoratorContext(arg: unknown): arg is MethodDecoratorContext {
218222
return (
219223
typeof arg === "object" &&
220224
arg !== null &&
@@ -223,12 +227,23 @@ function isNewDecoratorContext(
223227
);
224228
}
225229

230+
type WorkerMethod = (
231+
task: Task
232+
) => Promise<Omit<TaskResult, "workflowInstanceId" | "taskId">>;
233+
226234
export function worker(options: WorkerOptions) {
227-
return function <T extends (task: Task) => Promise<Omit<TaskResult, "workflowInstanceId" | "taskId">>>(
228-
target: T,
229-
propertyKeyOrContext?:
230-
| string
231-
| { kind: string; name: string | symbol },
235+
function decorator<T extends WorkerMethod>(
236+
value: T,
237+
context: MethodDecoratorContext
238+
): T | undefined;
239+
function decorator(
240+
target: object,
241+
propertyKey?: string,
242+
descriptor?: PropertyDescriptor
243+
): PropertyDescriptor | WorkerMethod | undefined;
244+
function decorator<T extends WorkerMethod>(
245+
target: T | object,
246+
propertyKeyOrContext?: string | MethodDecoratorContext,
232247
descriptor?: PropertyDescriptor
233248
): T | PropertyDescriptor | undefined {
234249
// Detect decorator API: new (Stage 3) vs legacy (experimentalDecorators)
@@ -334,7 +349,7 @@ export function worker(options: WorkerOptions) {
334349
});
335350

336351
if (isNewApi) {
337-
// New decorator API: return replacement function (cast to T for type compatibility)
352+
// New decorator API: return replacement function
338353
return dualModeFunction as unknown as T;
339354
}
340355

@@ -344,5 +359,7 @@ export function worker(options: WorkerOptions) {
344359
return descriptor;
345360
}
346361
return dualModeFunction as unknown as T;
347-
};
362+
}
363+
364+
return decorator;
348365
}

0 commit comments

Comments
 (0)