๋ฐ์ํ
๋ฌธ์
์กฐ๊ฑด `C`, ์ฐธ์ผ ๋ ๋ฐํํ๋ ํ์
`T`, ๊ฑฐ์ง์ผ ๋ ๋ฐํํ๋ ํ์
`F`๋ฅผ ๋ฐ๋ ํ์
`If`๋ฅผ ๊ตฌํํ์ธ์. `C`๋ `true` ๋๋ `false`์ด๊ณ , `T`์ `F`๋ ์๋ฌด ํ์
์
๋๋ค.
์์:
type A = If<true, 'a', 'b'> // expected to be 'a'
type B = If<false, 'a', 'b'> // expected to be 'b'
ํ์ด
type If<C extends boolean, T, F> = C extends true ? T : F
type์์ extends๊ฐ ๋ฑํธ ๋๊ฐ == ์ ํด๋นํ๋ค๊ณ ๋ณด๋ฉด ํธํ ๊ฒ ๊ฐ๋ค
์ถ์ฒ
https://github.com/type-challenges/type-challenges/blob/main/questions/00268-easy-if/README.ko.md
๋ฐ์ํ
'๐ Typescript > type-challenges' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[TS] type-challenges: 189 - Awaited (0) | 2023.07.17 |
---|---|
[TS] type-challenges: 43. Exclude (0) | 2023.07.14 |
[TS] type-challenges: 18. Length of Tuple (0) | 2023.07.05 |
[TS] type-challenges: 14. First of Array (0) | 2023.07.04 |
[TS] type-challenges : 11. Tuple to Object (0) | 2023.07.03 |