Skip to content

update #317

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
Jan 12, 2025
Merged
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
6 changes: 3 additions & 3 deletions modules/20-functions/85-function-overloads/ru/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ concat(1.33, 10); // 110

Для перегрузки необязательно использовать объявление функций. То же самое можно сделать с помощью стрелочной функции:

```
```typescript
const concat: {
(a: number, b: number): string;
(a: string, b: string): string;
} = (a: unknown, b: unknown) => {
} = (a, b) => {
if (typeof a === 'number' && typeof b === 'number') {
return `${a.toFixed()}${b.toFixed()}`;
}
Expand All @@ -54,7 +54,7 @@ type Overloaded = {
const concat: Overloaded = (a, b) => {...}
```

В этом случае не обязательно явно указывать типы параметров внутри функции. Это делается в объявлении функции.
В этом случае не обязательно явно указывать типы параметров внутри функции.

Перегрузка функций не ограничивается двумя версиями. Их может быть сколько угодно. Главное, что в конце всегда описывается функция, которая является общей по параметрам для всех вариантов и внутри которой описывается вся логика для каждого варианта.

Expand Down
Loading