Skip to content
Closed
Show file tree
Hide file tree
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
7 changes: 6 additions & 1 deletion modules/25-types/70-variability/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,10 @@ test('applyTransactions', () => {

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

expectTypeOf(wallet2.transactions[0].apply).returns.toExtend<number>();
expectTypeOf(wallet2.transactions[0].apply).parameters.toEqualTypeOf<
[number]
>();
expectTypeOf(wallet2.transactions[0].apply).returns.toEqualTypeOf<number>();
expectTypeOf(wallet2.balance).toEqualTypeOf<number>();
expectTypeOf(applyTransactions).returns.toEqualTypeOf<number>();
});
2 changes: 1 addition & 1 deletion modules/40-generics/20-generic-types/en/EXERCISE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
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.
2 changes: 1 addition & 1 deletion modules/40-generics/20-generic-types/ru/EXERCISE.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ s.has(1); // true
s.has(8); // false
```

Тип включает в себя два метода: `add()` и `has()`. Данные внутри должны храниться в свойстве `items`.
Тип включает в себя два метода: `add()` и `has()`. Оба принимают одно значение того же типа, что и элементы множества. `add()` возвращает число, `has()` — `boolean`. Данные внутри должны храниться в свойстве `items`.
12 changes: 8 additions & 4 deletions modules/40-generics/20-generic-types/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<boolean>();
expectTypeOf(s1.add).parameters.toEqualTypeOf<[number]>();
expectTypeOf(s1.add).returns.toEqualTypeOf<number>();
});

test('function', () => {
Expand All @@ -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<boolean>();
expectTypeOf(s1.add).parameters.toEqualTypeOf<[string]>();
expectTypeOf(s1.add).returns.toEqualTypeOf<number>();
});
10 changes: 8 additions & 2 deletions modules/40-generics/30-generic-functions/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<number>();
expectTypeOf(coll.filter).parameters.toEqualTypeOf<
[(value: number, index: number, array: Array<number>) => boolean]
>();
expectTypeOf(coll.filter).returns.toEqualTypeOf<MyArray<number>>();

const coll1: MyArray<string> = {
items: [],
Expand All @@ -31,5 +36,6 @@ test('MyArray', () => {
},
};

expectTypeOf(coll1.push).parameters.toExtend<[string]>();
expectTypeOf(coll1.push).parameters.toEqualTypeOf<[string]>();
expectTypeOf(coll1.filter).returns.toEqualTypeOf<MyArray<string>>();
});
4 changes: 2 additions & 2 deletions modules/50-objects/30-mapped-types/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -32,5 +32,5 @@ test('sanitize', () => {
limit: 10,
});

expectTypeOf(query).toExtend<{ page: number; limit: number }>();
expectTypeOf(query).toEqualTypeOf<{ page: number; limit: number }>();
});
2 changes: 1 addition & 1 deletion modules/50-objects/35-mapping-modifiers/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ test('deepFreeze', () => {
user.location.city = 'London';
}).toThrow();

expectTypeOf(user).toExtend<
expectTypeOf(user).toEqualTypeOf<
Readonly<{
name: string;
age: number;
Expand Down
2 changes: 2 additions & 0 deletions modules/50-objects/45-record/en/EXERCISE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
2 changes: 2 additions & 0 deletions modules/50-objects/45-record/ru/EXERCISE.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ console.log(isAdminAllowed); // => true
const isUserAllowed = checkUserAccess('user', 'adminPanel');
console.log(isUserAllowed); // => false
```

Возвращаемая функция принимает ровно два аргумента — роль и ресурс — и возвращает `boolean`. Типы аргументов задаются параметрами `createAccessChecker()`: в примере выше это `UserRole` и `UserResource`.
5 changes: 4 additions & 1 deletion modules/50-objects/45-record/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<boolean>();
});