You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix: Jest utilities types for TypeScript consumers - #11097
This pull request was authored by AI on behalf of @EnesKartal.
Summary
Since 4.6.0 the published types of the Jest utilities come from the web stub, so getAnimatedStyle is typed (): void and the matchers are missing for TypeScript consumers. The stub now takes its signatures from index.native.ts, which also brings in the jest.Matchers augmentation. Runtime behavior is unchanged.
yarn type:check:tests: the new jestUtilsTest.tst.ts fails on the web pass without the change and passes with it.
yarn type:check:consumer (part of type:check:tests, needs yarn build): type-checks __typetests__/consumer/ against the built lib/typescript through package.json#types, with moduleSuffixes unset and skipLibCheck off. With the stub from main it fails with the issue's errors (TS2554, TS2339, missing jest matchers); with this branch it passes.
Changelog
I added a changelog fragment with yarn changelog:add for each changed package, or this PR does not change react-native-reanimated or react-native-worklets.
No actionable comments were generated in the recent review.
Walkthrough
The web Jest utility stub now declares its exports with the corresponding native utility types. Its functions remain no-ops. Type tests cover utility arguments, the getAnimatedStyle return type, and Jest matcher members. A consumer type-check script validates fixtures against built declarations, and the package type-check script runs it. A changelog entry records the reported TypeScript typing issue.
Change: Bug fix · Severity of issue fixed: Medium
Merge Risk: Low · up to 17a31
The change fixes the published Jest utility types for TypeScript consumers. Web Jest tests can type-check the matchers and still fail at runtime, which the author describes as an existing gap, so owners should be aware of it. Merge-readiness risk is low.
Pre-merge checks: 4
Check name
Status
Explanation
Title check
The title names the main change: fixing the TypeScript types of the Jest utilities for consumers. It matches the changeset, which replaces the web Jest-utils stub declarations with the native signatur…
Description check
The description states the problem (published Jest utility types come from the web stub, so getAnimatedStyle and the matchers are mistyped), the fix (the stub takes signatures from index.native.ts), a…
Linked Issues check
[#11082] requires published Jest utility declarations to match the functions Jest runs. At the reviewed head, src/jestUtils/index.ts uses import type * as JestUtils from './index.native'. Each of …
Out of Scope Changes check
Each changed file supports the type fix for [#11082]. The index.ts change keeps the no-op web behavior. getAnimatedStyle returns undefined as never, which has no runtime effect beyond the prior …
Full details: Title check
Explanation
The title names the main change: fixing the TypeScript types of the Jest utilities for consumers. It matches the changeset, which replaces the web Jest-utils stub declarations with the native signatures and adds the jest.Matchers augmentation. The title uses the conventional fix: prefix and is short and specific.
Full details: Description check
Explanation
The description states the problem (published Jest utility types come from the web stub, so getAnimatedStyle and the matchers are mistyped), the fix (the stub takes signatures from index.native.ts), and the test plan (new jestUtilsTest.tst.ts and a consumer type check). These details match the changed files and the linked objectives.
Full details: Linked Issues check
Explanation
[#11082] requires published Jest utility declarations to match the functions Jest runs. At the reviewed head, src/jestUtils/index.ts uses import type * as JestUtils from './index.native'. Each of the five exports (withReanimatedTimer, advanceAnimationByTime, advanceAnimationByFrame, setUpTests, getAnimatedStyle) is typed as typeof JestUtils.<name>. This gives the stub the native signatures, including getAnimatedStyle returning DefaultStyle. The type-only import also brings the jest.Matchers augmentation into the published declaration chain, which covers the toHaveAnimatedStyle and toHaveAnimatedProps matcher requirement. The added consumer fixture (__typetests__/consumer/jestUtilsTest.ts) checks getAnimatedStyle arguments and the opacity result, setUpTests options, and both matcher types. package.json runs this check as part of type:check:tests. The author reports the consumer check fails on the main stub and passes on this branch. I did not rerun the checks. Remaining gap: web runtime does not register the matchers. The PR description states this gap predates the PR and is excluded from the issue scope.
Full details: Out of Scope Changes check
Explanation
Each changed file supports the type fix for [#11082]. The index.ts change keeps the no-op web behavior. getAnimatedStyle returns undefined as never, which has no runtime effect beyond the prior stub's no-op. The jestUtilsTest.tst.ts and __typetests__/consumer/ files are regression tests for the declarations. consumer/tsconfig.json and scripts/test-consumer-ts.sh run the consumer check without moduleSuffixes. The package.json change wires that check into type:check:tests. The changelog fragment documents the fix. No unrelated change is shown. The web matcher registration in setUpTests was excluded from this PR and is not part of this change.
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
The reason will be displayed to describe this comment to others. Learn more.
Follow-up Comments
Web type surface advertises matchers that the web Jest setup does not register.
6-9: Minor · Functional Correctness · Poor tradeoff
Web type surface advertises matchers that the web Jest setup does not register.
packages/react-native-reanimated/src/jestUtils/index.ts now imports ./index.native, so the jest.Matchers augmentation reaches web TypeScript programs. The web Jest project runs jest/setup.js, which calls the setUpTests stub in index.ts. That stub registers no matchers. A *.web.test.* file that calls toHaveAnimatedStyle or toHaveAnimatedProps now type-checks, but the call fails at runtime because the matcher is not registered.
Before this change, the same call produced a type error. The runtime gap existed before this PR. The change removes the compile-time signal.
Resolve this in one of two ways:
Register web implementations of both matchers in the web setUpTests.
Keep the native matcher augmentation out of the declarations that web TypeScript programs load. This requires moving the jest.Matchers declaration out of the import chain that index.ts uses.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
…ions
Add a consumer fixture that imports `react-native-reanimated` through
`package.json#types` (the built `lib/typescript`), with `moduleSuffixes`
unset and `skipLibCheck` off, so the repo tsconfig's `.native` suffix
preference can't hide what consumers read. It runs as part of
`type:check:tests`, after the build in CI.
Also document in the web stub why the `jest.Matchers` augmentation stays
in the published declarations.
Pushed a0bbcfe to address the two pieces of feedback.
CodeRabbit: web programs see the matcher types. I kept the jest.Matchers augmentation in the published declarations. package.json has a single types entry (lib/typescript/index.d.ts) and no exports/conditions, so lib/typescript/jestUtils/index.d.ts (built from the web stub) is the only jestUtils declaration file consumers' TypeScript reads, on native and on web. If the augmentation were moved out of the stub's import chain, native consumers would lose toHaveAnimatedStyle/toHaveAnimatedProps again, and #11082 asks for those. The cost: a web Jest test that calls these matchers type-checks but fails at runtime. That runtime gap was already there before this PR, and none of the repo's *.web.test.* files use these matchers. I added a comment in src/jestUtils/index.ts explaining the tradeoff. I didn't register the matchers in the web setUpTests because that would change runtime behavior, which is out of scope here.
Consumer regression check (suggested in #11082 (comment)). Added __typetests__/consumer/. It's a fixture that imports react-native-reanimated by its package name, so it resolves through package.json#types to the built lib/typescript. Its standalone tsconfig doesn't extend the repo config, so moduleSuffixes is unset, and it sets skipLibCheck: false. scripts/test-consumer-ts.sh runs it as yarn type:check:consumer, which is chained into type:check:tests. Both CI paths that run that (package static checks, TS compatibility check) build the package first. The script fails with a hint if lib/typescript is missing. With skipLibCheck off, react-native-svg's and react-native's own declarations report errors against the installed RN 0.88 types, and those errors aren't from this package. So the script only reports errors outside node_modules: the fixture plus the reanimated/worklets declarations, which currently have none. It isn't a literal npm pack + install. It resolves the same way an npm consumer does, but inside the workspace so the peer dependencies resolve. npm pack --dry-run confirms lib/typescript/jestUtils/index.d.ts ships.
Verification
yarn type:check:consumer with the stub from main, after rebuilding lib/typescript with bob build --target typescript:
jestUtilsTest.ts(9,12): error TS2554: Expected 0 arguments, but got 1.
jestUtilsTest.ts(11,43): error TS2554: Expected 0 arguments, but got 1.
jestUtilsTest.ts(11,58): error TS2339: Property 'opacity' does not exist on type 'void'.
jestUtilsTest.ts(13,1): error TS2578: Unused '@ts-expect-error' directive.
jestUtilsTest.ts(16,25): error TS2503: Cannot find namespace 'jest'.
With this branch: passes. --explainFiles shows the fixture reads lib/typescript/jestUtils/index.d.ts through the package entry.
yarn type:check:tests: passes (17 tstyche files, native and web passes, plus the consumer check). oxlint and oxfmt are clean on the changed files.
Add negative checks for the matcher argument lists.
The consumer fixture calls toHaveAnimatedStyle and toHaveAnimatedProps only with valid arguments. A declaration that accepts any argument list would still compile, so the fixture cannot detect that widening. The tstyche matcher tests also check only valid argument lists. Add @ts-expect-error calls that omit the required arguments, as the fixture already does for getAnimatedStyle().
Pushed 17a317e: the consumer fixture now has @ts-expect-error calls of toHaveAnimatedStyle() and toHaveAnimatedProps() without arguments, so a widened declaration would fail the check.
This branch has not been deployed
No deployments
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
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.
Note
This pull request was authored by AI on behalf of @EnesKartal.
Summary
Since 4.6.0 the published types of the Jest utilities come from the web stub, so
getAnimatedStyleis typed(): voidand the matchers are missing for TypeScript consumers. The stub now takes its signatures fromindex.native.ts, which also brings in thejest.Matchersaugmentation. Runtime behavior is unchanged.Fixes #11082
Test plan
yarn type:check:tests: the newjestUtilsTest.tst.tsfails on the web pass without the change and passes with it.yarn type:check:consumer(part oftype:check:tests, needsyarn build): type-checks__typetests__/consumer/against the builtlib/typescriptthroughpackage.json#types, withmoduleSuffixesunset andskipLibCheckoff. With the stub frommainit fails with the issue's errors (TS2554, TS2339, missingjestmatchers); with this branch it passes.Changelog
yarn changelog:addfor each changed package, or this PR does not changereact-native-reanimatedorreact-native-worklets.