Skip to content

update type checks #320

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 1, 2025
Merged
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
5 changes: 2 additions & 3 deletions modules/10-basics/20-typescript-as-a-second-language/test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import * as ta from 'type-assertions';
import { expect, test } from 'vitest';
import { expect, test, expectTypeOf } from 'vitest';

import multiply from './index';

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

ta.assert<ta.Equal<ReturnType<typeof multiply>, number>>();
expectTypeOf(multiply).returns.toMatchTypeOf<number>();
});
5 changes: 2 additions & 3 deletions modules/10-basics/30-variables/test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as ta from 'type-assertions';
import { expect, test } from 'vitest';
import { expect, test, expectTypeOf } from 'vitest';

import repeat from './index';

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

ta.assert<ta.Equal<ReturnType<typeof repeat>, string>>();
expectTypeOf(repeat).returns.toMatchTypeOf<string>();
});
5 changes: 2 additions & 3 deletions modules/10-basics/40-named-functions/test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as ta from 'type-assertions';
import { expect, test } from 'vitest';
import { expect, test, expectTypeOf } from 'vitest';

import getHiddenCard from './index';

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

ta.assert<ta.Equal<ReturnType<typeof getHiddenCard>, string>>();
expectTypeOf(getHiddenCard).returns.toMatchTypeOf<string>();
});
5 changes: 2 additions & 3 deletions modules/10-basics/45-anonymous-functions/test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import * as ta from 'type-assertions';
import { expect, test } from 'vitest';
import { expect, test, expectTypeOf } from 'vitest';

import getEvenNumbers from './index';

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

ta.assert<ta.Equal<ReturnType<typeof getEvenNumbers>, number[]>>();
expectTypeOf(getEvenNumbers).returns.toMatchTypeOf<number[]>();
});
5 changes: 2 additions & 3 deletions modules/10-basics/50-arrays/test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as ta from 'type-assertions';
import { expect, test } from 'vitest';
import { expect, test, expectTypeOf } from 'vitest';

import filterAnagrams from './index';

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

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

ta.assert<ta.Equal<ReturnType<typeof filterAnagrams>, string[]>>();
expectTypeOf(filterAnagrams).returns.toMatchTypeOf<string[]>();
});
7 changes: 3 additions & 4 deletions modules/10-basics/55-objects/test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as ta from 'type-assertions';
import { expect, test } from 'vitest';
import { expect, test, expectTypeOf } from 'vitest';

import isComplete from './index';

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

ta.assert<ta.Equal<ReturnType<typeof isComplete>, boolean>>();
ta.assert<ta.Equal<Parameters<typeof isComplete>[0], { name: string, lessons: string[] }>>();
expectTypeOf(isComplete).returns.toMatchTypeOf<boolean>();
expectTypeOf(isComplete).parameter(0).toMatchTypeOf<{ name: string, lessons: string[] }>();
});
5 changes: 2 additions & 3 deletions modules/10-basics/60-enums/test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as ta from 'type-assertions';
import { expect, test } from 'vitest';
import { expect, test, expectTypeOf } from 'vitest';

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

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

ta.assert<ta.Equal<ReturnType<typeof buildModal>, { text: string, status: ModalStatus }>>();
expectTypeOf(buildModal).returns.toMatchTypeOf<{ text: string, status: ModalStatus }>();
});
5 changes: 2 additions & 3 deletions modules/10-basics/70-type-aliases/test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as ta from 'type-assertions';
import { expect, test } from 'vitest';
import { expect, test, expectTypeOf } from 'vitest';

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

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

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

ta.assert<ta.Equal<ReturnType<typeof getOlderUser>, User | null>>();
expectTypeOf(getOlderUser).returns.toMatchTypeOf<User | null>();
});
5 changes: 2 additions & 3 deletions modules/25-types/20-union-types/test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as ta from 'type-assertions';
import { expect, test } from 'vitest';
import { expect, test, expectTypeOf } from 'vitest';

import lastIndex from './index';

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

ta.assert<ta.Equal<ReturnType<typeof lastIndex>, number | null>>();
expectTypeOf(lastIndex).returns.toMatchTypeOf<number | null>();
});
5 changes: 2 additions & 3 deletions modules/25-types/25-literal-types/test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as ta from 'type-assertions';
import { expect, test } from 'vitest';
import { expect, test, expectTypeOf } from 'vitest';

import startGame from './index';

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

ta.assert<ta.Equal<ReturnType<typeof makeTurn>, void>>();
expectTypeOf(makeTurn).returns.toMatchTypeOf<void>();
});
7 changes: 3 additions & 4 deletions modules/25-types/40-assignability/test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as ta from 'type-assertions';
import { expect, test } from 'vitest';
import { expect, test, expectTypeOf } from 'vitest';

import form from './index';

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

ta.assert<ta.Equal<Parameters<typeof nameValidator>, [string]>>();
ta.assert<ta.Equal<Parameters<typeof ageValidator>, [number]>>();
expectTypeOf(nameValidator).parameters.toMatchTypeOf<[string]>();
expectTypeOf(ageValidator).parameters.toMatchTypeOf<[number]>();
});
7 changes: 3 additions & 4 deletions modules/25-types/70-variability/test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as ta from 'type-assertions';
import { expect, test } from 'vitest';
import applyTransactions, { Transaction, Wallet } from './index';
import { expect, test, expectTypeOf } from 'vitest';
import applyTransactions, { Wallet } from './index';

test('applyTransactions', () => {
const wallet: Wallet = {
Expand Down Expand Up @@ -40,5 +39,5 @@ test('applyTransactions', () => {

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

ta.assert<ta.Equal<Parameters<Transaction['apply']>, [number]>>();
expectTypeOf(wallet2.transactions[0].apply).returns.toMatchTypeOf<number>();
});
5 changes: 2 additions & 3 deletions modules/40-generics/10-generics-overview/test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as ta from 'type-assertions';
import { expect, test } from 'vitest';
import { expect, test, expectTypeOf } from 'vitest';

import last from './index';

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

ta.assert<ta.Equal<ReturnType<typeof last<number>>, number | null>>();
expectTypeOf(last<number>).returns.toMatchTypeOf<number | null>();
});
11 changes: 5 additions & 6 deletions modules/40-generics/20-generic-types/test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as ta from 'type-assertions';
import { expect, test } from 'vitest';
import { expect, test, expectTypeOf } from 'vitest';

import MySet from './index';

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

ta.assert<ta.Equal<Parameters<typeof s1.has>, [number]>>();
ta.assert<ta.Equal<Parameters<typeof s1.add>, [number]>>();
expectTypeOf(s1.has).parameters.toMatchTypeOf<[number]>();
expectTypeOf(s1.add).parameters.toMatchTypeOf<[number]>();
});

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

ta.assert<ta.Equal<Parameters<typeof s1.has>, [string]>>();
ta.assert<ta.Equal<Parameters<typeof s1.add>, [string]>>();
expectTypeOf(s1.has).parameters.toMatchTypeOf<[string]>();
expectTypeOf(s1.add).parameters.toMatchTypeOf<[string]>();
});
19 changes: 15 additions & 4 deletions modules/40-generics/30-generic-functions/test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as ta from 'type-assertions';
import { expect, test } from 'vitest';
import { expect, test, expectTypeOf } from 'vitest';

import MyArray from './index';

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

ta.assert<ta.Equal<Parameters<MyArray<string>['push']>, [string]>>();
ta.assert<ta.Equal<ReturnType<MyArray<string>['push']>, number>>();
expectTypeOf(coll.push).parameters.toMatchTypeOf<[number]>();

const coll1: MyArray<string> = {
items: [],
push(value) {
return this.items.push(value);
},
filter(callback) {
const newItems = this.items.filter(callback);
return { ...this, items: newItems };
},
};

expectTypeOf(coll1.push).parameters.toMatchTypeOf<[string]>();
});
7 changes: 3 additions & 4 deletions modules/40-generics/40-many-parameters/test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as ta from 'type-assertions';
import { expect, test } from 'vitest';
import { expect, test, expectTypeOf } from 'vitest';

import MyMap from './index';

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

ta.assert<ta.Equal<Parameters<MyMap<string, number>['set']>, [string, number]>>();
ta.assert<ta.Equal<ReturnType<MyMap<string, number>['get']>, number | undefined>>();
expectTypeOf(map.set).parameters.toMatchTypeOf<[string, number]>();
expectTypeOf(map.get).returns.toMatchTypeOf<number | undefined>();
});
7 changes: 3 additions & 4 deletions modules/40-generics/50-async-functions/test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as ta from 'type-assertions';
import { expect, test } from 'vitest';
import { expect, test, expectTypeOf } from 'vitest';
import asyncMap from './index';

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

ta.assert<ta.Equal<typeof result, number[]>>();
ta.assert<ta.Equal<typeof result2, string[]>>();
expectTypeOf(result).toMatchTypeOf<number[]>();
expectTypeOf(result2).toMatchTypeOf<string[]>();
});
7 changes: 3 additions & 4 deletions modules/50-objects/30-mapped-types/test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as ta from 'type-assertions';
import { expect, test } from 'vitest';
import { expect, test, expectTypeOf } from 'vitest';

import sanitize from './index';

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

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

const params = {
page: 1,
Expand All @@ -33,5 +32,5 @@ test('sanitize', () => {
limit: 10,
});

ta.assert<ta.Equal<typeof query, { page: number; limit: number, }>>();
expectTypeOf(query).toMatchTypeOf<{ page: number; limit: number, }>();
});
7 changes: 3 additions & 4 deletions modules/50-objects/35-mapping-modifiers/test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as ta from 'type-assertions';
import { expect, test } from 'vitest';
import { expect, test, expectTypeOf } from 'vitest';

import deepFreeze from './index';

Expand Down Expand Up @@ -40,7 +39,7 @@ test('deepFreeze', () => {
user.location.city = 'London';
}).toThrow();

ta.assert<ta.Equal<typeof user, Readonly<{
expectTypeOf(user).toMatchTypeOf<Readonly<{
name: string,
age: number,
location: Readonly<{
Expand All @@ -50,5 +49,5 @@ test('deepFreeze', () => {
lon: number,
}>,
}>,
}>>>();
}>>();
});
5 changes: 2 additions & 3 deletions modules/50-objects/45-record/test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as ta from 'type-assertions';
import { expect, test } from 'vitest';
import { expect, test, expectTypeOf } from 'vitest';

import createAccessChecker from './index';

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

ta.assert<ta.Equal<Parameters<typeof checkUserAccess>, [UserRole, UserResource]>>();
expectTypeOf(checkUserAccess).parameters.toMatchTypeOf<[UserRole, UserResource]>();
});
8 changes: 1 addition & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
},
"type": "module",
"dependencies": {
"sinon": "^19.0.2",
"type-assertions": "^1.1.0"
"sinon": "^19.0.2"
},
"devDependencies": {
"@eslint/js": "^9.21.0",
Expand Down