From a6a67e38bc1a33302443db9bcab4d891554a42f5 Mon Sep 17 00:00:00 2001 From: Nikolay Gagarinov Date: Fri, 14 Aug 2026 17:10:43 +0500 Subject: [PATCH] =?UTF-8?q?test(type-matchers):=20=D0=BE=D1=82=D0=B2=D0=B5?= =?UTF-8?q?=D1=80=D0=B3=D0=B0=D1=82=D1=8C=20=D1=80=D0=B5=D1=88=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D1=8F=20=D0=BD=D0=B0=20any=20=D0=B2=20=D1=88=D0=B5=D1=81?= =?UTF-8?q?=D1=82=D0=B8=20=D1=83=D1=80=D0=BE=D0=BA=D0=B0=D1=85=20(#357)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/25-types/70-variability/test.ts | 7 ++++++- modules/40-generics/20-generic-types/en/EXERCISE.md | 2 +- modules/40-generics/20-generic-types/ru/EXERCISE.md | 2 +- modules/40-generics/20-generic-types/test.ts | 12 ++++++++---- modules/40-generics/30-generic-functions/test.ts | 10 ++++++++-- modules/50-objects/30-mapped-types/test.ts | 4 ++-- modules/50-objects/35-mapping-modifiers/test.ts | 2 +- modules/50-objects/45-record/en/EXERCISE.md | 2 ++ modules/50-objects/45-record/ru/EXERCISE.md | 2 ++ modules/50-objects/45-record/test.ts | 5 ++++- 10 files changed, 35 insertions(+), 13 deletions(-) diff --git a/modules/25-types/70-variability/test.ts b/modules/25-types/70-variability/test.ts index 78bb7a97..90713396 100644 --- a/modules/25-types/70-variability/test.ts +++ b/modules/25-types/70-variability/test.ts @@ -39,5 +39,10 @@ test('applyTransactions', () => { expect(applyTransactions(wallet2)).toBe(10); - expectTypeOf(wallet2.transactions[0].apply).returns.toExtend(); + expectTypeOf(wallet2.transactions[0].apply).parameters.toEqualTypeOf< + [number] + >(); + expectTypeOf(wallet2.transactions[0].apply).returns.toEqualTypeOf(); + expectTypeOf(wallet2.balance).toEqualTypeOf(); + expectTypeOf(applyTransactions).returns.toEqualTypeOf(); }); diff --git a/modules/40-generics/20-generic-types/en/EXERCISE.md b/modules/40-generics/20-generic-types/en/EXERCISE.md index 9314841e..d1e1a96e 100644 --- a/modules/40-generics/20-generic-types/en/EXERCISE.md +++ b/modules/40-generics/20-generic-types/en/EXERCISE.md @@ -11,4 +11,4 @@ s.has(1); // true s.has(8); // false ``` -The type includes two methods: `add()` and `has()`. The data inside must be stored in the `items` property. \ No newline at end of file +The type includes two methods: `add()` and `has()`. Both take a single value of the same type as the elements of the set. `add()` returns a number, `has()` returns a `boolean`. The data inside must be stored in the `items` property. \ No newline at end of file diff --git a/modules/40-generics/20-generic-types/ru/EXERCISE.md b/modules/40-generics/20-generic-types/ru/EXERCISE.md index 47b21c09..a508b125 100644 --- a/modules/40-generics/20-generic-types/ru/EXERCISE.md +++ b/modules/40-generics/20-generic-types/ru/EXERCISE.md @@ -11,4 +11,4 @@ s.has(1); // true s.has(8); // false ``` -Тип включает в себя два метода: `add()` и `has()`. Данные внутри должны храниться в свойстве `items`. +Тип включает в себя два метода: `add()` и `has()`. Оба принимают одно значение того же типа, что и элементы множества. `add()` возвращает число, `has()` — `boolean`. Данные внутри должны храниться в свойстве `items`. diff --git a/modules/40-generics/20-generic-types/test.ts b/modules/40-generics/20-generic-types/test.ts index c05a52a4..80510414 100644 --- a/modules/40-generics/20-generic-types/test.ts +++ b/modules/40-generics/20-generic-types/test.ts @@ -18,8 +18,10 @@ test('function', () => { s1.add(1); expect(s1.has(1)).toBe(true); - expectTypeOf(s1.has).parameters.toExtend<[number]>(); - expectTypeOf(s1.add).parameters.toExtend<[number]>(); + expectTypeOf(s1.has).parameters.toEqualTypeOf<[number]>(); + expectTypeOf(s1.has).returns.toEqualTypeOf(); + expectTypeOf(s1.add).parameters.toEqualTypeOf<[number]>(); + expectTypeOf(s1.add).returns.toEqualTypeOf(); }); test('function', () => { @@ -38,6 +40,8 @@ test('function', () => { s1.add('hexlet'); expect(s1.has('hexlet')).toBe(true); - expectTypeOf(s1.has).parameters.toExtend<[string]>(); - expectTypeOf(s1.add).parameters.toExtend<[string]>(); + expectTypeOf(s1.has).parameters.toEqualTypeOf<[string]>(); + expectTypeOf(s1.has).returns.toEqualTypeOf(); + expectTypeOf(s1.add).parameters.toEqualTypeOf<[string]>(); + expectTypeOf(s1.add).returns.toEqualTypeOf(); }); diff --git a/modules/40-generics/30-generic-functions/test.ts b/modules/40-generics/30-generic-functions/test.ts index eb5989e8..2fb905f6 100644 --- a/modules/40-generics/30-generic-functions/test.ts +++ b/modules/40-generics/30-generic-functions/test.ts @@ -18,7 +18,12 @@ test('MyArray', () => { expect(coll.push(2)).toBe(2); expect(coll.push(5)).toBe(3); - expectTypeOf(coll.push).parameters.toExtend<[number]>(); + expectTypeOf(coll.push).parameters.toEqualTypeOf<[number]>(); + expectTypeOf(coll.push).returns.toEqualTypeOf(); + expectTypeOf(coll.filter).parameters.toEqualTypeOf< + [(value: number, index: number, array: Array) => boolean] + >(); + expectTypeOf(coll.filter).returns.toEqualTypeOf>(); const coll1: MyArray = { items: [], @@ -31,5 +36,6 @@ test('MyArray', () => { }, }; - expectTypeOf(coll1.push).parameters.toExtend<[string]>(); + expectTypeOf(coll1.push).parameters.toEqualTypeOf<[string]>(); + expectTypeOf(coll1.filter).returns.toEqualTypeOf>(); }); diff --git a/modules/50-objects/30-mapped-types/test.ts b/modules/50-objects/30-mapped-types/test.ts index cb1f95da..c185a9f2 100644 --- a/modules/50-objects/30-mapped-types/test.ts +++ b/modules/50-objects/30-mapped-types/test.ts @@ -16,7 +16,7 @@ test('sanitize', () => { // eslint-disable-next-line @typescript-eslint/no-unused-vars const user = sanitize(obj, ['password']); - expectTypeOf(user).toExtend<{ name: string; age: number }>(); + expectTypeOf(user).toEqualTypeOf<{ name: string; age: number }>(); const params = { page: 1, @@ -32,5 +32,5 @@ test('sanitize', () => { limit: 10, }); - expectTypeOf(query).toExtend<{ page: number; limit: number }>(); + expectTypeOf(query).toEqualTypeOf<{ page: number; limit: number }>(); }); diff --git a/modules/50-objects/35-mapping-modifiers/test.ts b/modules/50-objects/35-mapping-modifiers/test.ts index 7e0e5112..d5c3faca 100644 --- a/modules/50-objects/35-mapping-modifiers/test.ts +++ b/modules/50-objects/35-mapping-modifiers/test.ts @@ -39,7 +39,7 @@ test('deepFreeze', () => { user.location.city = 'London'; }).toThrow(); - expectTypeOf(user).toExtend< + expectTypeOf(user).toEqualTypeOf< Readonly<{ name: string; age: number; diff --git a/modules/50-objects/45-record/en/EXERCISE.md b/modules/50-objects/45-record/en/EXERCISE.md index a9dcdc23..d00a3134 100644 --- a/modules/50-objects/45-record/en/EXERCISE.md +++ b/modules/50-objects/45-record/en/EXERCISE.md @@ -19,3 +19,5 @@ console.log(isAdminAllowed); // => true const isUserAllowed = checkUserAccess('user', 'adminPanel'); console.log(isUserAllowed); // => false ``` + +The returned function takes exactly two arguments — a role and a resource — and returns a `boolean`. The types of the arguments come from the parameters of `createAccessChecker()`: in the example above they are `UserRole` and `UserResource`. diff --git a/modules/50-objects/45-record/ru/EXERCISE.md b/modules/50-objects/45-record/ru/EXERCISE.md index b5638d3b..a775a5c5 100644 --- a/modules/50-objects/45-record/ru/EXERCISE.md +++ b/modules/50-objects/45-record/ru/EXERCISE.md @@ -19,3 +19,5 @@ console.log(isAdminAllowed); // => true const isUserAllowed = checkUserAccess('user', 'adminPanel'); console.log(isUserAllowed); // => false ``` + +Возвращаемая функция принимает ровно два аргумента — роль и ресурс — и возвращает `boolean`. Типы аргументов задаются параметрами `createAccessChecker()`: в примере выше это `UserRole` и `UserResource`. diff --git a/modules/50-objects/45-record/test.ts b/modules/50-objects/45-record/test.ts index 05bb0d58..e7aa772a 100644 --- a/modules/50-objects/45-record/test.ts +++ b/modules/50-objects/45-record/test.ts @@ -22,5 +22,8 @@ test('function', () => { const isUserAllowed = checkUserAccess('user', 'adminPanel'); expect(isUserAllowed).toBe(false); - expectTypeOf(checkUserAccess).parameters.toExtend<[UserRole, UserResource]>(); + expectTypeOf(checkUserAccess).parameters.toEqualTypeOf< + [UserRole, UserResource] + >(); + expectTypeOf(checkUserAccess).returns.toEqualTypeOf(); });