Skip to content
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

result of env.run is not inferring type, returning unknown #1601

Open
chadxz opened this issue Jan 17, 2025 · 3 comments
Open

result of env.run is not inferring type, returning unknown #1601

chadxz opened this issue Jan 17, 2025 · 3 comments
Labels
bug Something isn't working

Comments

@chadxz
Copy link
Contributor

chadxz commented Jan 17, 2025

What are you really trying to do?

I'm trying to test my activities using env.run and assert against the result.

Describe the bug

The return type of env.run is unknown when I would expect that it would be inferred from the activity.

Minimal Reproduction

https://codesandbox.io/p/devbox/l363c8

Environment/Versions

Macbook M2 Pro Sequoia 15.2
@temporal/testing 1.11.6

@chadxz chadxz added the bug Something isn't working label Jan 17, 2025
@chadxz chadxz changed the title [Bug] FILL_TITLE_HERE result of env.run is not inferring type, returning unknown Jan 17, 2025
@chadxz
Copy link
Contributor Author

chadxz commented Jan 17, 2025

I can work around the issue by passing explicit types to env.run, i.e.

        const result = await env.run<
          [UpdateCustomerRelationshipActivityInput],
          Nullable<UpdateCustomerRelationshipActivityResult>,
          typeof updateCustomerRelationship
        >(updateCustomerRelationship, {
          ...
        });

chadxz added a commit to chadxz/sdk-typescript that referenced this issue Jan 17, 2025
Why?
====

The types on MockActivityEnvironment.run() currently explicitly return
`unknown` which is annoying to work with.

How?
====

Instead of splitting the generic args, use the TypeScript built-in
utilities `Parameters<F>` and `ReturnType<F>` so that the types can be
properly inferred from the activity function.

----

Closes temporalio#1601.
@chadxz
Copy link
Contributor Author

chadxz commented Jan 17, 2025

@mjameswh here's a possible fix for this issue: chadxz@5884ef5

Main thing i'm not sure about is whether this would be considered a breaking change or not. I imagine if you were previously explicitly specifying the generic type parameters, a change like this may break you.

With the fix, you can see in the test suite that the return type is improved:

Image

@chadxz
Copy link
Contributor Author

chadxz commented Jan 25, 2025

Any thoughts on this? I'm happy to submit a PR, just want to make sure I take an appropriate approach.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant