[Bug]: Incorrect type deduction in test function when silencing errors in test data #15427
Closed
Description
Version
29.7.0
Steps to reproduce
- Clone the repo https://github.com/SmolPatat/jest-type-bug/tree/main
- Follow the README.
- Run
npm install
- Run
npm run validate
- Run
- TypeScript will throw an error.
Expected behavior
Since I explicitly specified the type in it.each
, this exact type should be used for the arguments of the test function, no matter what I do with the test data.
Actual behavior
Jest deduces some goofy types, even though it doesn't need to deduce anything, since it has the type explicitly provided to it. The types deduced are not valid and suggest dangerous changes that will make it fail at runtime.
Additional context
Omitting some object fields in the test data is a common practice. It should be possible to use the recommended solutions such as @ts-expect-error
or @ts-ignore
when the developer wants to only provide the data relevant to the test.
Environment
System:
OS: Linux 6.12 Fedora Linux 41 (Workstation Edition)
CPU: (8) x64 11th Gen Intel(R) Core(TM) i5-1135G7 @ 2.40GHz
Binaries:
Node: 20.12.2 - ~/.nvm/versions/node/v20.12.2/bin/node
Yarn: 1.22.22 - /usr/bin/yarn
npm: 10.9.1 - ~/.nvm/versions/node/v20.12.2/bin/npm
npmPackages:
jest: ^29.7.0 => 29.7.0