> For the complete documentation index, see [llms.txt](https://simian114.gitbook.io/blog/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://simian114.gitbook.io/blog/undefined/undefined-3/undefined/easy/04.-if.md).

# 04. If

[문제](https://github.com/type-challenges/type-challenges/blob/master/questions/268-easy-if/README.md)

[해설](https://ghaiklor.github.io/type-challenges-solutions/en/easy-if.html)

## 문제

Implement a utils `If` which accepts condition `C`, a truthy return type `T`, and a falsy return type `F`. `C` is expected to be either `true` or `false` while `T` and `F` can be any type.

For example:

```
type A = If<true, 'a', 'b'> // expected to be 'a'
type B = If<false, 'a', 'b'> // expected to be 'b'
```

## 풀이

```typescript
type If<C, T, F> = ?;

// 1. C는 True 또는 False 를 갖는다. 즉 Boolean 이다.제한을 걸자
type if<C extends boolean, T, F> = ?;

// 2. C 가 true라면 T 가 된다.
type if<C extends boolean, T, F> = C extends True ? T : F;
```

너무 간단한 문제였다. 끝!
