Skip to content

[Feature Request] Better type inference for MockActivityEnvironment.run #1710

Open
@TastyPi

Description

@TastyPi

Is your feature request related to a problem? Please describe.

This code:

async function foo(): Promise<string> {
  return "foo";
}
const result = await new MockActivityEnvironment().run(foo);
result.startsWith("foo");

Does not compile with strict types because result is inferred to be unknown instead of string.

Describe the solution you'd like

Change the signature of MockActivityEnvironment.run from:

run<P extends any[], R, F extends ActivityFunction<P, R>>(fn: F, ...args: P): Promise<R>;

to

run<F extends ActivityFunction>(fn: F, ...args: Parameters<F>): ReturnType<F>

I've checked this locally and it makes my example infer the type of result correctly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions