> For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt.

# Rstest types

Rstest exports its public TypeScript types from `@rstest/core`. Use `import type` so these imports are erased from runtime output.

```ts
import type { Mock, Mocked, RstestConfig } from '@rstest/core';
```

## Configuration types

Use these types when you need to type a config object, a config factory, or shared config utilities outside `defineConfig`.

```ts
import type {
  ProjectConfig,
  RstestConfig,
  RstestConfigAsyncFn,
  RstestConfigExport,
  RstestConfigSyncFn,
} from '@rstest/core';
```

- `RstestConfig`: The top-level Rstest configuration type.
- `RstestConfigSyncFn`: A synchronous function that returns `RstestConfig`.
- `RstestConfigAsyncFn`: An asynchronous function that returns `RstestConfig`.
- `RstestConfigExport`: The union accepted by a Rstest config file.
- `ProjectConfig`: The type for a standalone [Rstest Project](/guide/basic/projects.md) config.

For most config files, prefer [`defineConfig`](/api/javascript-api/rstest-core.md#defineconfig), [`defineProject`](/api/javascript-api/rstest-core.md#defineproject), and [`defineInlineProject`](/api/javascript-api/rstest-core.md#defineinlineproject) because they preserve autocomplete without requiring explicit annotations.

## Test API types

Use these types when extending test APIs, defining reusable helpers, or typing custom fixtures.

```ts
import type {
  Describe,
  Expect,
  ExpectStatic,
  FixtureCleanup,
  FixtureLifecycle,
  Rstest,
  RstestUtilities,
  TestContext,
} from '@rstest/core';
```


[Added in v0.10.1](https://github.com/web-infra-dev/rstest/releases/tag/v0.10.1)

`TestContext` is available as a public type export starting in Rstest 0.10.1.


[Added in v0.11.7](https://github.com/web-infra-dev/rstest/releases/tag/v0.11.7)

`FixtureCleanup` and `FixtureLifecycle` support the named fixture form starting in Rstest 0.11.7.

- `Rstest`: The full runtime API shape, including `test`, `describe`, `expect`, hooks, and `rs` / `rstest` utilities.
- `RstestUtilities`: The type of the `rs` and `rstest` utility objects.
- `TestContext`: The context object passed to test callbacks and lifecycle hooks.
- `Describe`: The type of the `describe` API.
- `Expect`: The assertion type returned by `expect(value)`.
- `ExpectStatic`: The callable `expect` API type.
- `FixtureCleanup`: A cleanup callback registered by a named fixture.
- `FixtureLifecycle`: The lifecycle object that provides `onCleanup` to a named fixture.

## Mock types

Use mock types when a helper accepts mock functions, spies, or mocked modules.

```ts
import type { Mock, Mocked, MockInstance } from '@rstest/core';
```

### Mock

`Mock<T>` represents a callable mock function created by [`rs.fn`](/api/runtime-api/rstest/mock-functions.md#rsfn). It preserves the parameters and return type of `T` while adding mock control APIs.

```ts
import { rs } from '@rstest/core';
import type { Mock } from '@rstest/core';

type LoadUser = (id: string) => Promise<{ name: string }>;

const loadUser: Mock<LoadUser> = rs.fn<LoadUser>();
loadUser.mockResolvedValue({ name: 'Jack' });
```

### MockInstance


[Added in v0.10.1](https://github.com/web-infra-dev/rstest/releases/tag/v0.10.1)

`MockInstance<T>` represents the shared mock control API on both `rs.fn()` mocks and `rs.spyOn()` spies. Use it when a helper only needs mock methods such as `mockClear`, `mockReset`, or `mockRestore` and does not need to call the mock function directly.

```ts
import type { MockInstance } from '@rstest/core';

function resetTrackedMock(mock: MockInstance) {
  mock.mockReset();
}
```

When you create a mock or spy inline, you usually do not need to annotate it because TypeScript can infer the type.

```ts
const spy = rs.spyOn(service, 'loadUser');
spy.mockResolvedValue({ name: 'Jack' });
```

### Mocked

`Mocked<T>` wraps an object or module type so its methods are typed as mocks. This is useful after [`rs.mock`](/api/runtime-api/rstest/mock-modules.md#rsmock), [`rs.mockObject`](/api/runtime-api/rstest/mock-functions.md#rsmockobject), or [`rs.mocked`](/api/runtime-api/rstest/mock-functions.md#rsmocked).

```ts
import { rs } from '@rstest/core';
import type { Mocked } from '@rstest/core';
import * as userApi from './userApi';

rs.mock('./userApi');

const mockedUserApi: Mocked<typeof userApi> = rs.mocked(userApi);
mockedUserApi.loadUser.mockResolvedValue({ name: 'Jack' });
```

## Reporter and result types

Use these types when creating custom reporters or external tools that consume Rstest results.

```ts
import type {
  Reporter,
  TestCaseInfo,
  TestFileInfo,
  TestFileResult,
  TestResult,
  TestSuiteInfo,
} from '@rstest/core';
```

For reporter implementation details, see [Reporter](/api/javascript-api/reporter.md).


[Added in v0.11.1](https://github.com/web-infra-dev/rstest/releases/tag/v0.11.1)

The result `meta` fields contain JSON-serializable metadata initialized from `TestOptions.meta` and written at runtime through `context.task.meta`. Suite metadata is inherited by descendant suites and tests with child top-level keys overriding parent keys; inherited values are copied for each descendant so runtime mutation does not leak between siblings. `TestFileResult.meta` contains metadata written by file-level `beforeAll` / `afterAll` hooks through `ctx.meta`, and suite results passed to `onTestSuiteResult` contain metadata written by that suite's lifecycle hooks.

```ts
import { afterAll, test } from '@rstest/core';

afterAll((ctx) => {
  ctx.meta.fileTag = 'mutation-run';
});

test('records metadata', { meta: { owner: 'stryker' } }, (ctx) => {
  ctx.task.meta.hitCount = 1;
});
```

## Assertion types

Use `Assertion` or `ExpectStatic` when typing custom assertion helpers.

```ts
import type { Assertion, ExpectStatic } from '@rstest/core';

function expectVisible(
  expect: ExpectStatic,
  value: HTMLElement,
): Assertion<HTMLElement> {
  return expect(value);
}
```

## Rsbuild type

Rstest re-exports `Rspack` from `@rsbuild/core` for integrations that need to type Rsbuild or Rspack hooks while staying on the same dependency graph as Rstest.

```ts
import type { Rspack } from '@rstest/core';
```
