-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
test.each()
: Accept a readonly (as const
) table properly
#14565
Conversation
Without this, TypeScript infers the types strangely such that it tries to assign the readonly argument list from the table to a mutable argument list type in the test function signature. This change correctly infers the argument list in the test function as readonly, which resolves the error.
✅ Deploy Preview for jestjs ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify site configuration. |
test.each()
: Accept a readonly table properlytest.each()
: Accept a readonly (as const
) table properly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks!
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Summary
Sometimes the inferred types in a
test.each()
table are too wide for the test that uses them. For instance, consider this test in whichletterCase
has to be specifically'upper'
or'lower'
:You can keep the literal types of the table values by giving it
as const
, but that causes a different (stranger) error:TypeScript appears to infer the type of the argument list as mutable, and then tries to assign the readonly argument tuple to it, which is an error. But we don't actually need the argument list to be mutable, so we want to tell TypeScript to consider it readonly as well. This type change does that, and makes the error go away.
Test plan
I believe as long as this test (and the rest of the suite) passes, it's safe. To verify, see that the test fails without this type change, and that everything passes with it.