Skip to content

[Bug]: Incorrect type deduction in test function when silencing errors in test data #15427

Closed
@SmolPatat

Description

Version

29.7.0

Steps to reproduce

  1. Clone the repo https://github.com/SmolPatat/jest-type-bug/tree/main
  2. Follow the README.
    1. Run npm install
    2. Run npm run validate
  3. 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

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions