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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @TastyPi

      Issue actions

        [Feature Request] Better type inference for `MockActivityEnvironment.run` · Issue #1710 · temporalio/sdk-typescript