Skip to content
Open
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
4 changes: 2 additions & 2 deletions src/task_1/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
* который написан в функции logObj компилировался и исполнялся корректно
*/

type FooType = unknown;
type BarType = unknown;
type FooType = {stringProp:string,numberProp:number,barObject:BarType};
type BarType = {stringsArrayProp:Array<string>,numbersOrDatesArrayProp:Array<Date|number>,functionProp:Function};

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Зачтено на 3 балла

export const fooObjects: FooType[] = [
{
Expand Down
9 changes: 7 additions & 2 deletions src/task_3/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@
* использовать тип any для типизации параметров запрещено
* функция должна возвращать сумму двух аргументов
*/
function add(x: string, y: string): string;
function add(x: number, y: number): number;
function add(x: string | number, y: string | number): string | number {
if (typeof x === 'string' && typeof y === 'string')
return x + y;
if (typeof x === 'number' && typeof y === 'number')
return x + y;
throw new Error;
}

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Зачтено на 3 балла

add('20', '21'); //2021
add(20, 21); //41
8 changes: 8 additions & 0 deletions src/task_4/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,11 @@ type FooType = {
a: number
b: string
};

/*
1)FooType можно расширить с помощью других type, а IFoo нельзя
2)Eсли объявить 2 interface IFoo, при использовании они будут объединены вместе,мы получим доступ к полям в первом и втором interface,
type не может иметь несколько объявлений.
3)type - создает новое имя для типа, inteface - обеспечивает способ определения сущностей.
4)type не может быть реализован,только объявлен,а члены interface реализуются производным классом.
*/
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Зачтено на 3 балла

2 changes: 1 addition & 1 deletion src/task_5/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export function logPerson(person: Person) {
console.log(` - ${person.name}, ${person.age}, ${additionalInformation}`);
}

export function filterUsers(persons: Person[], criteria: User): User[] {
export function filterUsers(persons: Person[], criteria: {type?: string, name?: string, age?: number, occupation?: string}): User[] {
return persons.filter(isUser).filter((user) => {
const criteriaKeys = Object.keys(criteria);
return criteriaKeys.every((fieldName) => {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Зачтено на 3 балла

Expand Down