diff --git a/src/task_1/index.ts b/src/task_1/index.ts index 3edb7b9..6ffbdee 100644 --- a/src/task_1/index.ts +++ b/src/task_1/index.ts @@ -3,8 +3,17 @@ * который написан в функции logObj компилировался и исполнялся корректно */ -type FooType = unknown; -type BarType = unknown; +type FooType = { + stringProp: String, + numberProp: Number, + barObject: BarType, +}; + +type BarType = { + stringsArrayProp: Array, + numbersOrDatesArrayProp: Array, + functionProp(flag: boolean): void, +}; export const fooObjects: FooType[] = [ { diff --git a/src/task_2/index.ts b/src/task_2/index.ts index 00b4939..66b60e8 100644 --- a/src/task_2/index.ts +++ b/src/task_2/index.ts @@ -70,7 +70,9 @@ const obj7: ThirdType = { const array = [obj1, obj2, obj3, obj4, obj5, obj6, obj7]; -function filter(array: Array, type: string) { +function filter(array: Array, type: string) +{ + return array.filter((x): x is FirstType | SecondType | ThirdType => typeof x === type); } filter(array, 'FirstType'); diff --git a/src/task_3/index.ts b/src/task_3/index.ts index b7c9cdc..85706e6 100644 --- a/src/task_3/index.ts +++ b/src/task_3/index.ts @@ -8,5 +8,10 @@ function add(x: string, y: string): string; function add(x: number, y: number): number; +function add(x: any, y: any): any +{ + return x+y; +} + 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..15e2b66 100644 --- a/src/task_4/index.ts +++ b/src/task_4/index.ts @@ -12,3 +12,15 @@ type FooType = { a: number b: string }; + +/** + * type не поддерживает изменения и наследования, может обЪеденять в себе другие, позволяет задать псевдоним + * для любой разновидности типа + */ + + +/** + * interface можно изменять и расширять, при создании нового interface с уже использованным именем они сольются + * в один, 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) => {