From 117f04dd000e6f9c74de12c9a8b52aaae115ead7 Mon Sep 17 00:00:00 2001 From: Iago Rodrigues Date: Thu, 28 Aug 2025 10:04:30 -0300 Subject: [PATCH 1/3] docs(custom_matchers): make it clear the difference between match interfaces --- .../01.solution.custom-matchers/README.mdx | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/exercises/03.assertions/01.solution.custom-matchers/README.mdx b/exercises/03.assertions/01.solution.custom-matchers/README.mdx index 04bde47..8b8a452 100644 --- a/exercises/03.assertions/01.solution.custom-matchers/README.mdx +++ b/exercises/03.assertions/01.solution.custom-matchers/README.mdx @@ -44,6 +44,16 @@ There are two interfaces from `vitest` that I extend using module augmentgation: - `Assertion`, which controls the matchers returned by calling `expect()`; - `MatchersDeclaration`, which annotates the matcher declarations passed to `expect.extend()`. +Since Vitest 3.2, you can extend the `Matchers` interface to have type-safe assertions in `expect.extend`, `expect().*` and `expect.*` methods at the same time. + +```diff ts filename=vitest.setup.ts add=3 remove=2,3 highlight=3 +declare module 'vitest' { +- interface Assertion extends CustomMatchers {} +- interface MatchersDeclaration extends CustomMatchers {} ++ interface Matchers extends CustomMatchers {} +} +``` + This is enough for the `.toMatchSchema()` custom matcher to be recognized by TypeScript: ```ts nonumber nocopy From 257fe1574c5084f8c91a6d0c2fe52e848128455e Mon Sep 17 00:00:00 2001 From: Iago Rodrigues Date: Thu, 28 Aug 2025 14:37:18 -0300 Subject: [PATCH 2/3] Update custom_matchers new interface --- .../01.solution.custom-matchers/README.mdx | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/exercises/03.assertions/01.solution.custom-matchers/README.mdx b/exercises/03.assertions/01.solution.custom-matchers/README.mdx index 8b8a452..8931799 100644 --- a/exercises/03.assertions/01.solution.custom-matchers/README.mdx +++ b/exercises/03.assertions/01.solution.custom-matchers/README.mdx @@ -34,25 +34,13 @@ interface CustomMatchers { } declare module 'vitest' { - interface Assertion extends CustomMatchers {} - interface MatchersDeclaration extends CustomMatchers {} + interface Matchers extends CustomMatchers {} } ``` -There are two interfaces from `vitest` that I extend using module augmentgation: - -- `Assertion`, which controls the matchers returned by calling `expect()`; -- `MatchersDeclaration`, which annotates the matcher declarations passed to `expect.extend()`. - -Since Vitest 3.2, you can extend the `Matchers` interface to have type-safe assertions in `expect.extend`, `expect().*` and `expect.*` methods at the same time. +This is the interface from `vitest` that I extend using module augmentation: -```diff ts filename=vitest.setup.ts add=3 remove=2,3 highlight=3 -declare module 'vitest' { -- interface Assertion extends CustomMatchers {} -- interface MatchersDeclaration extends CustomMatchers {} -+ interface Matchers extends CustomMatchers {} -} -``` +- `Matchers`, which controls the matchers returned by calling `expect()` and annotates the matcher declarations passed to `expect.extend()`. This is enough for the `.toMatchSchema()` custom matcher to be recognized by TypeScript: From cc4181c9aa549ea397e26f25eb2a81690de4db78 Mon Sep 17 00:00:00 2001 From: Artem Zakharchenko Date: Thu, 28 Aug 2025 21:27:20 +0200 Subject: [PATCH 3/3] 03/01: polish the `Matchers` explanation --- .../03.assertions/01.solution.custom-matchers/README.mdx | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/exercises/03.assertions/01.solution.custom-matchers/README.mdx b/exercises/03.assertions/01.solution.custom-matchers/README.mdx index 8931799..2562262 100644 --- a/exercises/03.assertions/01.solution.custom-matchers/README.mdx +++ b/exercises/03.assertions/01.solution.custom-matchers/README.mdx @@ -38,9 +38,7 @@ declare module 'vitest' { } ``` -This is the interface from `vitest` that I extend using module augmentation: - -- `Matchers`, which controls the matchers returned by calling `expect()` and 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: