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

[Feature]: support type inference for function parameters #15034

Closed
eyalroth opened this issue Apr 24, 2024 · 5 comments · Fixed by #15129
Closed

[Feature]: support type inference for function parameters #15034

eyalroth opened this issue Apr 24, 2024 · 5 comments · Fixed by #15129

Comments

@eyalroth
Copy link
Contributor

🚀 Feature Proposal

This is identical to #13267, which was implemented in https://github.com/jestjs/jest/releases/tag/v29.1.0 (#13268), but was soon reverted in https://github.com/jestjs/jest/releases/tag/v29.1.2.

So in fact, the feature remains unimplemented.

Motivation

Faster detection of broken function signatures + allow IDEs to auto rename the test parameters when renaming the original function parameters.

Example

No response

Pitch

Seeing that this feature request was opened here in the past, I assume it fits here still.

Copy link

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days.

@github-actions github-actions bot added the Stale label May 24, 2024
@SimenB
Copy link
Member

SimenB commented May 24, 2024

PR very much welcome - as noted in #13339 there are some regression tests added, so hopefully we won't have the same problems.

@github-actions github-actions bot removed the Stale label May 24, 2024
eyalroth pushed a commit to eyalroth/jest that referenced this issue Jun 15, 2024
eyalroth added a commit to eyalroth/jest that referenced this issue Jun 15, 2024
eyalroth added a commit to eyalroth/jest that referenced this issue Jun 15, 2024
eyalroth added a commit to eyalroth/jest that referenced this issue Jun 18, 2024
@eyalroth
Copy link
Contributor Author

@SimenB Hey :) I started working on a PR in draft mode.

Before completing it, I wanted to know if that's the right direction.

I also had two specific questions about the PR:

  1. I added an import type from jest-mock to jest-types package.
    Should I change something in the dependencies?

  2. The type-checking of "examples and tests" (yarn typecheck:tests) fails on a few cases:
    a) In throwMatcher.test.ts, mockedMatch is defined with jest.fn and a no-args function, causing later expect to fail since it passes an argument to toHaveBeenCalledWith.
    b) In Farm.test.ts the same is happening with computeWorkerKey.
    c) In BaseWorkerPool.test.ts the type of the argument given to expect(Worker).toHaveBeenNthCalledWith() does not exactly match the type of the mock argument (WorkerOptions).

These failures seems to me like the expected behavior of this new feature, meaning that it's likely to introduce breaking changes to existing code. What are your thoughts on this?

eyalroth added a commit to eyalroth/jest that referenced this issue Jun 22, 2024
eyalroth added a commit to eyalroth/jest that referenced this issue Jun 22, 2024
eyalroth added a commit to eyalroth/jest that referenced this issue Jun 22, 2024
eyalroth added a commit to eyalroth/jest that referenced this issue Jun 22, 2024
eyalroth added a commit to eyalroth/jest that referenced this issue Jun 24, 2024
eyalroth added a commit to eyalroth/jest that referenced this issue Jun 24, 2024
eyalroth added a commit to eyalroth/jest that referenced this issue Jun 24, 2024
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 27, 2024
@SimenB
Copy link
Member

SimenB commented Aug 8, 2024

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants