[Feature]: Replace `@types/jest`'s `expect` implementation with `@jest/expect`
See original GitHub issueš Feature Proposal
People might not want to use the globals (expect, test etc.) Jest provides (either because of ESM or just a preference). And because Jest is written in TypeScript, when doing e.g. import {expect} from '@jest/globals' all built in matchers are typed. However, if you use some matchers from the community (such as jest-extended), they augment the matchers from @types/jest instead of expect (or @jest/expect). If instead all libraries augmented the actual expect types, the imported matcher would be typed correctly.
However, this flips the problem - now people using the globals no longer get custom matchers typed! The solution to this problem is to make @jest/types use @jest/expect instead of shipping its own types for this.
This issue is for tracking the work that needs to be done before releasing Jest 28 stable so thereās a single source of truth - the source code.
I have started: https://github.com/SimenB/DefinitelyTyped/tree/jest-expect
We need to make sure the tests pass. Most breakage is due to the tests using e.g. jest.InverseMatchers etc - I donāt think thatās super useful? I might be wrong though, in which case we should expose more of those types from expect and/or @jest/expect.
~(note that running tests is āimpossibleā until https://github.com/microsoft/DefinitelyTyped-tools/pull/411 is merged. I ran npm install manually inside types/jest to see errors in the tests in my IDE)~
/cc @mrazauskas
Issue Analytics
- State:
- Created 2 years ago
- Reactions:3
- Comments:8 (4 by maintainers)

Top Related StackOverflow Question
If this issue is resolved, yes š As of now
@types/jestdoesnāt get its matchers fromexpectFor anyone following along, weāve replace our own usage of
@types/jestwith the types exported from@jest/globalsand an extra package sticking Jestās globals into TSās globals: #13344.Iād still love for
@types/jestto work with@jest/expect, but that might just be https://github.com/DefinitelyTyped/DefinitelyTyped/pull/62037 or something like it instead of having steps on the way