TypeScript Jest Matchers functions are typed any #2261
Unanswered
bozhanglab49
asked this question in
Q&A
Replies: 2 comments 3 replies
-
In tests in a dynamically typed language like javascript (typescript is just for compile time), you'd ideally want to test for different types of values as well. For example, if a function accepts only a |
Beta Was this translation helpful? Give feedback.
2 replies
-
Jest typing is defined in |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Jest doesn't type some of its expect functions in Matchers. For example, it doesn't generate compiling errors for following code:
Here is how toEqual and toHaveReturnedWith are declared:
Obviously, parameters of both are typed any. Even though it allows you to specify a type, it is not bound with the actual value. They can be improved like this:
Now TypeScript complains:
My question is why jest chooses not to type them like above which is obviously better?
Beta Was this translation helpful? Give feedback.
All reactions