Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
TastyPi opened this issue May 8, 2025 · 0 comments · May be fixed by #1711
Open

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

TastyPi opened this issue May 8, 2025 · 0 comments · May be fixed by #1711
Labels
enhancement New feature or request

Comments

@TastyPi
Copy link

TastyPi commented May 8, 2025

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.

@TastyPi TastyPi added the enhancement New feature or request label May 8, 2025
TastyPi added a commit to TastyPi/sdk-typescript that referenced this issue May 8, 2025
@TastyPi TastyPi linked a pull request May 8, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant