diff --git a/src/task_1/index.ts b/src/task_1/index.ts index 3edb7b9..e36a0f2 100644 --- a/src/task_1/index.ts +++ b/src/task_1/index.ts @@ -3,8 +3,8 @@ * который написан в функции logObj компилировался и исполнялся корректно */ -type FooType = unknown; -type BarType = unknown; +type FooType = {stringProp:string,numberProp:number,barObject:BarType}; +type BarType = {stringsArrayProp:Array,numbersOrDatesArrayProp:Array,functionProp:Function}; export const fooObjects: FooType[] = [ { diff --git a/src/task_3/index.ts b/src/task_3/index.ts index b7c9cdc..bccac64 100644 --- a/src/task_3/index.ts +++ b/src/task_3/index.ts @@ -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; +} add('20', '21'); //2021 add(20, 21); //41 \ No newline at end of file diff --git a/src/task_4/index.ts b/src/task_4/index.ts index e884df8..f2b2f8a 100644 --- a/src/task_4/index.ts +++ b/src/task_4/index.ts @@ -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 реализуются производным классом. +*/ diff --git a/src/task_5/index.ts b/src/task_5/index.ts index ef3e0c0..988e02e 100644 --- a/src/task_5/index.ts +++ b/src/task_5/index.ts @@ -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) => {