-
Notifications
You must be signed in to change notification settings - Fork 15
Михалев Кирилл #16
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
base: master
Are you sure you want to change the base?
Михалев Кирилл #16
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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; | ||
| } | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Зачтено на 3 балла |
||
| add('20', '21'); //2021 | ||
| add(20, 21); //41 | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 реализуются производным классом. | ||
| */ | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Зачтено на 3 балла |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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) => { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Зачтено на 3 балла |
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Зачтено на 3 балла