---
title: Function overload
description:
tags:
- typescript
- overload
date: 2023-08-05
---
함수 오버로딩는 다음과 같은 상황에서 사용될 수 있다.
```typescript
function returnWhatIPassIn(t: number): number;
function returnWhatIPassIn(t: string): string;
function returnWhatIPassIn(t: unknown) {
return t;
}
const one = returnWhatIPassIn(1);
const jun = returnWhatIPassIn("jun");
```
`returnWhatIPassIn`라는 함수는 단순히 입력값을 반환하는 함수이다. 대부분의 함수가 이런 간단한 형태는 아니겠지만 핵심은 **하나의 함수를 선언했는데 다양한 인자를 받을 수 있는 함수**라는 것이다. 인자에 숫자, 문자열을 넘겨도 `returnWhatIPassIn`는 타입에 상관없이 처리할 수 있다.
함수 오버로딩은 매개 변수를 다르게 하여 중복해서 함수를 선언하는 것이다.
---
참조 강의: https://inf.run/FVDi