Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,11 @@ interface CustomMatchers<MatcherResult = any> {
}

declare module 'vitest' {
interface Assertion<T = any> extends CustomMatchers<T> {}
interface MatchersDeclaration extends CustomMatchers {}
interface Matchers<T> extends CustomMatchers<T> {}
}
```

There are two interfaces from `vitest` that I extend using module augmentgation:

- `Assertion<T>`, which controls the matchers returned by calling `expect()`;
- `MatchersDeclaration`, which annotates the matcher declarations passed to `expect.extend()`.
Here, I'm augmenting the `Matchers` type from `vitest` with my custom `CustomMatchers` type. By doing so, I'm extending the type definitions for the `expect()` function as well as the argument type of `expect.extend()` for later.

This is enough for the `.toMatchSchema()` custom matcher to be recognized by TypeScript:

Expand Down
Loading