Skip to content

fix: Jest utilities types for TypeScript consumers - #11097

Open
EnesKartal wants to merge 4 commits into
software-mansion:mainfrom
EnesKartal:fix/jest-utils-types-11082
Open

EnesKartal wants to merge 4 commits into
software-mansion:mainfrom
EnesKartal:fix/jest-utils-types-11082

Conversation

@EnesKartal

@EnesKartal EnesKartal commented Oct 30, 2026 •

Copy link
Copy Markdown

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 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.

Fixes #11082

Test plan

  • 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.

@coderabbitai

coderabbitai Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

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: Passed 4

Check name Status Explanation
Title check Passed 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 Passed 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 Passed [#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 Passed 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.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 1d6b673e-1679-4e92-bf88-bc9bdd8d01cc
Commits

Reviewing files that changed from the base of the PR and between 130deaf and 17a317e.

Files selected for processing: 1

  • packages/react-native-reanimated/__typetests__/consumer/jestUtilsTest.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Follow-up Comments

Minor follow-up 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.

Open the source location


Review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 5b8b52ce-a9e4-4b41-84a5-635ac26a490c
Commits

Reviewing files that changed from the base of the PR and between c51fd79 and f348819.

Files selected for processing: 3
  • packages/react-native-reanimated/__typetests__/jestUtilsTest.tst.ts
  • packages/react-native-reanimated/changelog/jest-utils-types-11082.fix.md
  • packages/react-native-reanimated/src/jestUtils/index.ts

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.
@EnesKartal

Copy link
Copy Markdown
Author

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.

@coderabbitai coderabbitai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Follow-up Comments

Nitpick Add negative checks for the matcher argument lists.

17-18: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

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().

🧪 Suggested fix
 declare const matchers: jest.Matchers<void>;
 matchers.toHaveAnimatedStyle({ opacity: 1 }, { shouldMatchAllProps: true });
 matchers.toHaveAnimatedProps({ text: 'text' });
+
+// @ts-expect-error `toHaveAnimatedStyle` requires a style
+matchers.toHaveAnimatedStyle();
+// @ts-expect-error `toHaveAnimatedProps` requires props
+matchers.toHaveAnimatedProps();

Open the source location

Comment thread scripts/test-consumer-ts.sh Resolved
@EnesKartal

EnesKartal commented Nov 13, 2026 •

Copy link
Copy Markdown
Author

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

getAnimatedStyle is typed (): void since 4.6.0 (published types describe the web stub)

1 participant