Skip to content

feat: export UserEventInstance type - #1967

Open
psjostrom wants to merge 1 commit into
callstack:mainfrom
psjostrom:export-user-event-instance-type
Open

psjostrom wants to merge 1 commit into
callstack:mainfrom
psjostrom:export-user-event-instance-type

Conversation

@psjostrom

@psjostrom psjostrom commented Nov 26, 2026 •

Copy link
Copy Markdown

Summary

  • Export the UserEventInstance type from the package root, next to UserEventConfig.
  • setup() declares UserEventInstance as its return type, and the setup() docs show it.
  • src/user-event/index.ts re-exports both interfaces with export type. A plain export made Babel emit a getter for each interface in dist/user-event/index.js, and the getter returns undefined.

We have a test helper that returns { screen, user }. To name the type of user, it imports from @testing-library/react-native/dist/user-event/setup, and that path broke when v14 moved build/ to dist/. The other option is ReturnType<typeof userEvent.setup>. #1091 exported RenderResult and RenderHookResult for the same reason.

Test plan

  • yarn validate passes, with 955 tests.
  • In an app on 14.1.0, import type { RenderResult, UserEventInstance } from '@testing-library/react-native' fails with TS2305. With this branch's build in node_modules, the same import typechecks, and the app's tests that use the helper pass.
  • dist/user-event/index.js from yarn build has no UserEventConfig or UserEventInstance export.

`userEvent.setup()` returns a `UserEventInstance`, but the package exports only
`UserEventConfig`. A helper that returns or receives the instance had to import
the type from `dist/user-event/setup` or write `ReturnType<typeof userEvent.setup>`.
`RenderResult` and `RenderHookResult` are exported for the same reason.

`setup()` now declares `UserEventInstance` as its return type, so the exported
type cannot drift from what `setup()` returns. `src/user-event/index.ts`
re-exports both interfaces with `export type`. A plain `export` made Babel emit
a getter for each interface in `dist/user-event/index.js` that returns
`undefined`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@psjostrom
psjostrom marked this pull request as ready for review November 26, 2026 15:39

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant