Skip to content

Commit 9a277a4

Browse files
authored
Merge pull request #320 from hexlet-basics/update-type-assertions
update type checks
2 parents a18b91d + 75d6db5 commit 9a277a4

File tree

22 files changed

+65
-80
lines changed

22 files changed

+65
-80
lines changed
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
import * as ta from 'type-assertions';
2-
import { expect, test } from 'vitest';
1+
import { expect, test, expectTypeOf } from 'vitest';
32

43
import multiply from './index';
54

65
test('multiply', () => {
76
expect(multiply(1, 3)).toBe(3);
87

9-
ta.assert<ta.Equal<ReturnType<typeof multiply>, number>>();
8+
expectTypeOf(multiply).returns.toMatchTypeOf<number>();
109
});
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import * as ta from 'type-assertions';
2-
import { expect, test } from 'vitest';
1+
import { expect, test, expectTypeOf } from 'vitest';
32

43
import repeat from './index';
54

@@ -8,5 +7,5 @@ test('repeat', () => {
87
expect(repeat('s', 2)).toBe('ss');
98
expect(repeat('s', 0)).toBe('');
109

11-
ta.assert<ta.Equal<ReturnType<typeof repeat>, string>>();
10+
expectTypeOf(repeat).returns.toMatchTypeOf<string>();
1211
});
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import * as ta from 'type-assertions';
2-
import { expect, test } from 'vitest';
1+
import { expect, test, expectTypeOf } from 'vitest';
32

43
import getHiddenCard from './index';
54

@@ -9,5 +8,5 @@ test('getHiddenCard', () => {
98
expect(getHiddenCard('1234123412344321', 2)).toEqual('**4321');
109
expect(getHiddenCard('1234123412341234', 12)).toEqual('************1234');
1110

12-
ta.assert<ta.Equal<ReturnType<typeof getHiddenCard>, string>>();
11+
expectTypeOf(getHiddenCard).returns.toMatchTypeOf<string>();
1312
});
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
import * as ta from 'type-assertions';
2-
import { expect, test } from 'vitest';
1+
import { expect, test, expectTypeOf } from 'vitest';
32

43
import getEvenNumbers from './index';
54

65
test('function', () => {
76
expect(getEvenNumbers()).toEqual([8, 100, 34]);
87

9-
ta.assert<ta.Equal<ReturnType<typeof getEvenNumbers>, number[]>>();
8+
expectTypeOf(getEvenNumbers).returns.toMatchTypeOf<number[]>();
109
});

modules/10-basics/50-arrays/test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import * as ta from 'type-assertions';
2-
import { expect, test } from 'vitest';
1+
import { expect, test, expectTypeOf } from 'vitest';
32

43
import filterAnagrams from './index';
54

@@ -10,5 +9,5 @@ test('function', () => {
109

1110
expect(filterAnagrams('laser', ['lazing', 'lazy', 'lacer'])).toEqual([]);
1211

13-
ta.assert<ta.Equal<ReturnType<typeof filterAnagrams>, string[]>>();
12+
expectTypeOf(filterAnagrams).returns.toMatchTypeOf<string[]>();
1413
});

modules/10-basics/55-objects/test.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import * as ta from 'type-assertions';
2-
import { expect, test } from 'vitest';
1+
import { expect, test, expectTypeOf } from 'vitest';
32

43
import isComplete from './index';
54

@@ -22,6 +21,6 @@ test('function', () => {
2221
};
2322
expect(isComplete(course3)).toBe(true);
2423

25-
ta.assert<ta.Equal<ReturnType<typeof isComplete>, boolean>>();
26-
ta.assert<ta.Equal<Parameters<typeof isComplete>[0], { name: string, lessons: string[] }>>();
24+
expectTypeOf(isComplete).returns.toMatchTypeOf<boolean>();
25+
expectTypeOf(isComplete).parameter(0).toMatchTypeOf<{ name: string, lessons: string[] }>();
2726
});

modules/10-basics/60-enums/test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import * as ta from 'type-assertions';
2-
import { expect, test } from 'vitest';
1+
import { expect, test, expectTypeOf } from 'vitest';
32

43
import buildModal, { ModalStatus } from './index';
54

@@ -10,5 +9,5 @@ test('function', () => {
109
expect(buildModal('code-basics', ModalStatus.Closed))
1110
.toEqual({ text: 'code-basics', status: ModalStatus.Closed });
1211

13-
ta.assert<ta.Equal<ReturnType<typeof buildModal>, { text: string, status: ModalStatus }>>();
12+
expectTypeOf(buildModal).returns.toMatchTypeOf<{ text: string, status: ModalStatus }>();
1413
});

modules/10-basics/70-type-aliases/test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import * as ta from 'type-assertions';
2-
import { expect, test } from 'vitest';
1+
import { expect, test, expectTypeOf } from 'vitest';
32

43
import getOlderUser, { User } from './index';
54

@@ -24,5 +23,5 @@ test('function', () => {
2423

2524
expect(getOlderUser(user2, user3)).toBeNull();
2625

27-
ta.assert<ta.Equal<ReturnType<typeof getOlderUser>, User | null>>();
26+
expectTypeOf(getOlderUser).returns.toMatchTypeOf<User | null>();
2827
});
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import * as ta from 'type-assertions';
2-
import { expect, test } from 'vitest';
1+
import { expect, test, expectTypeOf } from 'vitest';
32

43
import lastIndex from './index';
54

@@ -10,5 +9,5 @@ test('lastIndex', () => {
109
expect(lastIndex(str, 'e')).toBe(5);
1110
expect(lastIndex(str, 'p')).toBeNull();
1211

13-
ta.assert<ta.Equal<ReturnType<typeof lastIndex>, number | null>>();
12+
expectTypeOf(lastIndex).returns.toMatchTypeOf<number | null>();
1413
});

modules/25-types/25-literal-types/test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import * as ta from 'type-assertions';
2-
import { expect, test } from 'vitest';
1+
import { expect, test, expectTypeOf } from 'vitest';
32

43
import startGame from './index';
54

@@ -26,5 +25,5 @@ test('startTurtleGame', () => {
2625
makeTurn('left');
2726
expect(state).toEqual([null, null, null, 'turtle', null]);
2827

29-
ta.assert<ta.Equal<ReturnType<typeof makeTurn>, void>>();
28+
expectTypeOf(makeTurn).returns.toMatchTypeOf<void>();
3029
});
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import * as ta from 'type-assertions';
2-
import { expect, test } from 'vitest';
1+
import { expect, test, expectTypeOf } from 'vitest';
32

43
import form from './index';
54

@@ -10,6 +9,6 @@ test('form', () => {
109
expect(nameValidator(form.name.value)).toBe(true);
1110
expect(ageValidator(form.age.value)).toBe(false);
1211

13-
ta.assert<ta.Equal<Parameters<typeof nameValidator>, [string]>>();
14-
ta.assert<ta.Equal<Parameters<typeof ageValidator>, [number]>>();
12+
expectTypeOf(nameValidator).parameters.toMatchTypeOf<[string]>();
13+
expectTypeOf(ageValidator).parameters.toMatchTypeOf<[number]>();
1514
});

modules/25-types/70-variability/test.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import * as ta from 'type-assertions';
2-
import { expect, test } from 'vitest';
3-
import applyTransactions, { Transaction, Wallet } from './index';
1+
import { expect, test, expectTypeOf } from 'vitest';
2+
import applyTransactions, { Wallet } from './index';
43

54
test('applyTransactions', () => {
65
const wallet: Wallet = {
@@ -40,5 +39,5 @@ test('applyTransactions', () => {
4039

4140
expect(applyTransactions(wallet2)).toBe(10);
4241

43-
ta.assert<ta.Equal<Parameters<Transaction['apply']>, [number]>>();
42+
expectTypeOf(wallet2.transactions[0].apply).returns.toMatchTypeOf<number>();
4443
});
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import * as ta from 'type-assertions';
2-
import { expect, test } from 'vitest';
1+
import { expect, test, expectTypeOf } from 'vitest';
32

43
import last from './index';
54

@@ -8,5 +7,5 @@ test('function', () => {
87
expect(last([3, 4])).toBe(4);
98
expect(last(['cat', 'dog'])).toBe('dog');
109

11-
ta.assert<ta.Equal<ReturnType<typeof last<number>>, number | null>>();
10+
expectTypeOf(last<number>).returns.toMatchTypeOf<number | null>();
1211
});

modules/40-generics/20-generic-types/test.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import * as ta from 'type-assertions';
2-
import { expect, test } from 'vitest';
1+
import { expect, test, expectTypeOf } from 'vitest';
32

43
import MySet from './index';
54

@@ -19,8 +18,8 @@ test('function', () => {
1918
s1.add(1);
2019
expect(s1.has(1)).toBe(true);
2120

22-
ta.assert<ta.Equal<Parameters<typeof s1.has>, [number]>>();
23-
ta.assert<ta.Equal<Parameters<typeof s1.add>, [number]>>();
21+
expectTypeOf(s1.has).parameters.toMatchTypeOf<[number]>();
22+
expectTypeOf(s1.add).parameters.toMatchTypeOf<[number]>();
2423
});
2524

2625
test('function', () => {
@@ -39,6 +38,6 @@ test('function', () => {
3938
s1.add('hexlet');
4039
expect(s1.has('hexlet')).toBe(true);
4140

42-
ta.assert<ta.Equal<Parameters<typeof s1.has>, [string]>>();
43-
ta.assert<ta.Equal<Parameters<typeof s1.add>, [string]>>();
41+
expectTypeOf(s1.has).parameters.toMatchTypeOf<[string]>();
42+
expectTypeOf(s1.add).parameters.toMatchTypeOf<[string]>();
4443
});

modules/40-generics/30-generic-functions/test.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import * as ta from 'type-assertions';
2-
import { expect, test } from 'vitest';
1+
import { expect, test, expectTypeOf } from 'vitest';
32

43
import MyArray from './index';
54

@@ -19,6 +18,18 @@ test('MyArray', () => {
1918
expect(coll.push(2)).toBe(2);
2019
expect(coll.push(5)).toBe(3);
2120

22-
ta.assert<ta.Equal<Parameters<MyArray<string>['push']>, [string]>>();
23-
ta.assert<ta.Equal<ReturnType<MyArray<string>['push']>, number>>();
21+
expectTypeOf(coll.push).parameters.toMatchTypeOf<[number]>();
22+
23+
const coll1: MyArray<string> = {
24+
items: [],
25+
push(value) {
26+
return this.items.push(value);
27+
},
28+
filter(callback) {
29+
const newItems = this.items.filter(callback);
30+
return { ...this, items: newItems };
31+
},
32+
};
33+
34+
expectTypeOf(coll1.push).parameters.toMatchTypeOf<[string]>();
2435
});

modules/40-generics/40-many-parameters/test.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import * as ta from 'type-assertions';
2-
import { expect, test } from 'vitest';
1+
import { expect, test, expectTypeOf } from 'vitest';
32

43
import MyMap from './index';
54

@@ -21,6 +20,6 @@ test('MyMap', () => {
2120
expect(map.get('two')).toBe(2);
2221
expect(map.get('three')).toBe(undefined);
2322

24-
ta.assert<ta.Equal<Parameters<MyMap<string, number>['set']>, [string, number]>>();
25-
ta.assert<ta.Equal<ReturnType<MyMap<string, number>['get']>, number | undefined>>();
23+
expectTypeOf(map.set).parameters.toMatchTypeOf<[string, number]>();
24+
expectTypeOf(map.get).returns.toMatchTypeOf<number | undefined>();
2625
});

modules/40-generics/50-async-functions/test.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import * as ta from 'type-assertions';
2-
import { expect, test } from 'vitest';
1+
import { expect, test, expectTypeOf } from 'vitest';
32
import asyncMap from './index';
43

54
test('asyncMap', async () => {
@@ -15,6 +14,6 @@ test('asyncMap', async () => {
1514
);
1615
expect(result3).toEqual([0, 2]);
1716

18-
ta.assert<ta.Equal<typeof result, number[]>>();
19-
ta.assert<ta.Equal<typeof result2, string[]>>();
17+
expectTypeOf(result).toMatchTypeOf<number[]>();
18+
expectTypeOf(result2).toMatchTypeOf<string[]>();
2019
});

modules/50-objects/30-mapped-types/test.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import * as ta from 'type-assertions';
2-
import { expect, test } from 'vitest';
1+
import { expect, test, expectTypeOf } from 'vitest';
32

43
import sanitize from './index';
54

@@ -17,7 +16,7 @@ test('sanitize', () => {
1716
// eslint-disable-next-line @typescript-eslint/no-unused-vars
1817
const user = sanitize(obj, ['password']);
1918

20-
ta.assert<ta.Equal<typeof user, { name: string; age: number }>>();
19+
expectTypeOf(user).toMatchTypeOf<{ name: string; age: number }>();
2120

2221
const params = {
2322
page: 1,
@@ -33,5 +32,5 @@ test('sanitize', () => {
3332
limit: 10,
3433
});
3534

36-
ta.assert<ta.Equal<typeof query, { page: number; limit: number, }>>();
35+
expectTypeOf(query).toMatchTypeOf<{ page: number; limit: number, }>();
3736
});

modules/50-objects/35-mapping-modifiers/test.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import * as ta from 'type-assertions';
2-
import { expect, test } from 'vitest';
1+
import { expect, test, expectTypeOf } from 'vitest';
32

43
import deepFreeze from './index';
54

@@ -40,7 +39,7 @@ test('deepFreeze', () => {
4039
user.location.city = 'London';
4140
}).toThrow();
4241

43-
ta.assert<ta.Equal<typeof user, Readonly<{
42+
expectTypeOf(user).toMatchTypeOf<Readonly<{
4443
name: string,
4544
age: number,
4645
location: Readonly<{
@@ -50,5 +49,5 @@ test('deepFreeze', () => {
5049
lon: number,
5150
}>,
5251
}>,
53-
}>>>();
52+
}>>();
5453
});

modules/50-objects/45-record/test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import * as ta from 'type-assertions';
2-
import { expect, test } from 'vitest';
1+
import { expect, test, expectTypeOf } from 'vitest';
32

43
import createAccessChecker from './index';
54

@@ -21,5 +20,5 @@ test('function', () => {
2120
const isUserAllowed = checkUserAccess('user', 'adminPanel');
2221
expect(isUserAllowed).toBe(false);
2322

24-
ta.assert<ta.Equal<Parameters<typeof checkUserAccess>, [UserRole, UserResource]>>();
23+
expectTypeOf(checkUserAccess).parameters.toMatchTypeOf<[UserRole, UserResource]>();
2524
});

package-lock.json

Lines changed: 1 addition & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
},
66
"type": "module",
77
"dependencies": {
8-
"sinon": "^19.0.2",
9-
"type-assertions": "^1.1.0"
8+
"sinon": "^19.0.2"
109
},
1110
"devDependencies": {
1211
"@eslint/js": "^9.21.0",

0 commit comments

Comments
 (0)