From 599689e957fb75a4bea8a776f50d39d6eb4a203e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Per=20Sj=C3=B6str=C3=B6m?= <37512275+psjostrom@users.noreply.github.com> Date: Thu, 26 Nov 2026 16:28:35 +0100 Subject: [PATCH] feat: export UserEventInstance type `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`. `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 --- docs/api/user-event.md | 4 ++-- src/pure.ts | 2 +- src/user-event/index.ts | 2 +- src/user-event/setup/setup.ts | 2 +- website/docs/14.x/docs/api/events/user-event.mdx | 4 ++-- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/docs/api/user-event.md b/docs/api/user-event.md index b5a5ba6b2..040257616 100644 --- a/docs/api/user-event.md +++ b/docs/api/user-event.md @@ -14,7 +14,7 @@ If User Event supports a given interaction, prefer it over the Fire Event counte userEvent.setup(options?: { delay?: number; advanceTimers?: (delay: number) => Promise | void; -}) +}): UserEventInstance ``` Example @@ -23,7 +23,7 @@ Example const user = userEvent.setup(); ``` -Creates a User Event object instance, which can be used to trigger events. +Creates a User Event object instance, which can be used to trigger events. Its type, `UserEventInstance`, is exported from the package, so a helper that returns or receives the instance can name it. ### Options diff --git a/src/pure.ts b/src/pure.ts index 377c1f678..62cd5bab3 100644 --- a/src/pure.ts +++ b/src/pure.ts @@ -16,4 +16,4 @@ export { userEvent } from './user-event'; export type { RenderOptions, RenderResult, DebugFunction } from './render'; export type { RenderHookOptions, RenderHookResult } from './render-hook'; export type { Config } from './config'; -export type { UserEventConfig } from './user-event'; +export type { UserEventConfig, UserEventInstance } from './user-event'; diff --git a/src/user-event/index.ts b/src/user-event/index.ts index fad60a88a..0f30ff855 100644 --- a/src/user-event/index.ts +++ b/src/user-event/index.ts @@ -6,7 +6,7 @@ import type { ScrollToOptions } from './scroll'; import { setup } from './setup'; import type { TypeOptions } from './type'; -export { UserEventConfig } from './setup'; +export type { UserEventConfig, UserEventInstance } from './setup'; export const userEvent = { setup, diff --git a/src/user-event/setup/setup.ts b/src/user-event/setup/setup.ts index 257d3627a..8b564668d 100644 --- a/src/user-event/setup/setup.ts +++ b/src/user-event/setup/setup.ts @@ -59,7 +59,7 @@ const defaultOptions: Required = { * @param options * @returns UserEvent instance */ -export function setup(options?: UserEventSetupOptions) { +export function setup(options?: UserEventSetupOptions): UserEventInstance { const config = createConfig(options, setup); const instance = createInstance(config); return instance; diff --git a/website/docs/14.x/docs/api/events/user-event.mdx b/website/docs/14.x/docs/api/events/user-event.mdx index bdbc968b0..480e6fc06 100644 --- a/website/docs/14.x/docs/api/events/user-event.mdx +++ b/website/docs/14.x/docs/api/events/user-event.mdx @@ -14,7 +14,7 @@ If User Event supports a given interaction, prefer it over the Fire Event counte userEvent.setup(options?: { delay?: number; advanceTimers?: (delay: number) => Promise | void; -}) +}): UserEventInstance ``` Example @@ -23,7 +23,7 @@ Example const user = userEvent.setup(); ``` -Creates a User Event object instance, which can be used to trigger events. +Creates a User Event object instance, which can be used to trigger events. Its type, `UserEventInstance`, is exported from the package, so a helper that returns or receives the instance can name it. ### Options {#setup-options}