Skip to content

Simplify the type of MockActivityEnvironment.run #1711

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
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

TastyPi
Copy link

@TastyPi TastyPi commented May 8, 2025

What was changed

Simplified the type of MockActivityEnvironment.run

Why?

Improves the type inference of the return type.

This example:

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

Does not currently compile with strict types because result is inferred as unknown instead of string. This change makes the type inference work correctly.

Checklist

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

  2. How was this tested:

Made the change on my local machine and saw the red squiggly lines disappear.

  1. Any docs updates needed?

I don't know, this is technically a breaking change if anyone is currently setting the type parameters.

@TastyPi TastyPi requested a review from a team as a code owner May 8, 2025 17:04
@mjameswh
Copy link
Contributor

mjameswh commented May 8, 2025

Thanks!

At the moment, CI isn't passing. See my comments for hints on how to resolve these.

You may also add a test in test-mockactivityenv.rs using the exact code snippet you showed above. Basically:

test('MockActivityEnvironment return type is correctly inferred', async (t) => {
  async function foo(): Promise<string> {
    return 'foo';
  }
  const result = await new MockActivityEnvironment().run(foo);
  // There should be no compile time error on this line
  result.startsWith('foo');
  t.pass();
});

@TastyPi
Copy link
Author

TastyPi commented May 9, 2025

Thanks for the review @mjameswh, admittedly I just did a quick edit in GitHub's integrated editor, sorry for not doing it properly 😅

I've made the changes you suggested, and I think it's all good now. I tried running npm run test in my repo, but a lot of seemingly unrelated tests failed, I'm not sure if I just haven't got my local environment set up correctly or if that is expected.

@TastyPi TastyPi requested a review from mjameswh May 9, 2025 10:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature Request] Better type inference for MockActivityEnvironment.run
2 participants