Skip to content

Commit

Permalink
feat(@jest/expect): Expose type of actual to Matchers
Browse files Browse the repository at this point in the history
Matchers isn't as typed as some users would like (see jestjs#13334, jestjs#13812).
For users who want to customize it by extending the `Matchers`
interface, it's useful to have access to the type of `actual` (the
argument of `expect`) so you can do, say,
```ts
interface Matchers<R, T> {
    toTypedEqual(expected: T): R
}
```
This commit exposes it. The first-party matchers still have the same
types as before.
  • Loading branch information
benjaminjkraft committed Jan 31, 2023
1 parent 836157f commit 4bfbc6b
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -2,6 +2,8 @@

### Features

- `[@jest/expect]` provide type of `actual` as a generic argument to `Matchers` to allow better-typed extensions (#TBD)

### Fixes

### Chore & Maintenance
Expand Down
2 changes: 1 addition & 1 deletion packages/expect/src/types.ts
Expand Up @@ -134,7 +134,7 @@ type PromiseMatchers = {
resolves: Matchers<Promise<void>> & Inverse<Matchers<Promise<void>>>;
};

export interface Matchers<R extends void | Promise<void>> {
export interface Matchers<R extends void | Promise<void>, T = unknown> {
/**
* Ensures the last call to a mock function was provided specific args.
*/
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-expect/src/types.ts
Expand Up @@ -29,7 +29,7 @@ type Inverse<Matchers> = {
not: Matchers;
};

type JestMatchers<R extends void | Promise<void>, T> = Matchers<R> &
type JestMatchers<R extends void | Promise<void>, T> = Matchers<R, T> &
SnapshotMatchers<R, T>;

type PromiseMatchers<T = unknown> = {
Expand Down

0 comments on commit 4bfbc6b

Please sign in to comment.