Repository navigation
fix: augment expect module so matcher types survive other augmentations - #1969
Open
shahjahanpak wants to merge 1 commit into
Open
shahjahanpak wants to merge 1 commit into
shahjahanpak wants to merge 1 commit into
Conversation
Fixes callstack#1968. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #1968.
The matcher types augmented
@jest/expect. In Jest 29 and Jest 30,@jest/expectdoes not declareMatchers; it re-exports it fromexpect. When TypeScript reads another augmentation ofexpectafter the library's types (for example
expo-router/testing-library, which augmentsexpectinbuild/testing-library/expect.d.ts), the augmentation through the re-export is dropped. Everymatcher call on the
@jest/globalsexpectthen fails withTS2339, although the matchers workat runtime. With
skipLibCheck: false, the old block also reportsTS2428, because it declaresMatcherswith one type parameter andexpectdeclares two.This PR augments
expectdirectly, with the same type parameters as Jest 29 and 30(
<R extends void | Promise<void>, T = unknown>), and removes the@jest/expectblock:expectblock in place, a build that keeps the@jest/expectblock gives the sameresult in every case of the matrix below, so the old block adds nothing.
@ts-expect-errorfails as unused (TS2578) as soon as the program imports@jest/globals, which the new regression test does.The global
jestnamespace block is unchanged. The globalexpectfrom@types/jestwas notaffected by this defect.
Test plan
src/matchers/__tests__/jest-globals-types.test.tsx: it augmentsexpectwith atest-only matcher and calls the built-in matchers on the
@jest/globalsexpect.yarn typecheckon the oldtypes.tsfails:yarn build,npm pack) installed in isolated projects with TypeScript 6.0.3,React Native 0.88.0-rc.1, and either Jest 30 (
expect@30.5.2) or Jest 29 (expect@29.7.0).The test file is the one from the issue. Matrix:
skipLibChecktrue or false;@jest/globalsonly, or also the global
expectwith@types/jest; and these extraexpectaugmentations:none, a local file that loads first, a local file imported after the library, a package
imported after the library (two type parameters), and a package imported after the library
with one type parameter (the
expo-routerform).TS2339oneach matcher call, on Jest 29 and Jest 30. With
skipLibCheck: falseit also reportsTS2428.A local file that loads first does not trigger the defect.
skipLibCheck: false, the error countfrom other packages' types is the same before and after.
expectcannot be resolved), withskipLibChecktrue andfalse: no error from this library, before or after.
yarn validate(typecheck, 956 tests, lint, format) andyarn typecheck:react-19_2pass.Not tested: pnpm and Yarn PnP layouts, TypeScript versions other than 6.0.3, and a real
expo-routerinstall (simulated by a package with the same declaration).🤖 Generated with Claude Code