2023๋ 12์ 6์ผ ๊ธฐ์ค Interface over Type Alias๋ก ์๊ฐ์ ๋ฐ๊ฟจ๋ค.
TypeScript ๊ณต์ ๋ฌธ์์ ์ธํฐ๋ท์ ๊ธ ๋๋ค์๋ Interface over Type Alias๋ฅผ ๊ถ์ฅํ๋ค. ๊ณผ๊ฑฐ์๋ Type Alias๋ฅผ extends ๋๋ implements์ ๋์์ผ๋ก ์ฌ์ฉํ ์ ์์๋ค. ๋ฐ๋ผ์ Interface๋ฅผ ์ฌ์ฉํ๋ ๊ฒ์ด ์์ ํ๊ณ ํธํ๋ค. ํ์ํ ๊ฒฝ์ฐ, ์ฆ Interface๋ฅผ ์ฌ์ฉํ์ง ๋ชปํ๋ ๊ฒฝ์ฐ์๋ง Type Alias๋ฅผ ์ฌ์ฉํ๋ค.
ํ์ฌ๋ Type Alias๋ฅผ extends ๋๋ implements์ ๋์์ผ๋ก ์ฌ์ฉํ ์ ์๋ค. ์ด์ ๋ ๋จ์ํ ํธํ๋ค๋ ์ด์ ๋ง์ผ๋ก Interface over Type Alias๋ฅผ ๊ถ์ฅํ ์ ์๋ค.
๋๋ถ๋ถ์ ์ฌ๋๋ค์ Interface์ Type์ ๋ค์์ฒ๋ผ ์ดํดํ๋ค. ๊ฐ์ฒด ์งํฅ ํจ๋ฌ๋ค์์ ๊ทผ๊ฑฐํ์ฌ ๊ฐ์ฒด ๋ช ์ธ๋ฅผ ์ ์ธํ๋ Interface. ๋ชจ๋ ํ์ (Primitive, Object, Function, etc...)์ ๋ํด ์ ์ด๋ฆ์ ์ ์ธํ๋ Type.
Type Alias over Interface
Interface์ ๋ง์ ๊ธฐ๋ฅ์ Type Alias๋ก ๋์ฒดํ ์ ์๋ ์ ์ ์ด์ฉํ์ฌ, ์คํ๋ ค Interface๋ฅผ ์ ํํ์ฌ ์ฌ์ฉํ๋ ๊ฒ์ ์ด๋จ๊น? Interface๋ฅผ Object Literal์ Type ์ ์ธ์ด ์๋ ํ์ฅ ๊ธฐ๋ฅ์ ์ฉ๋๋ก๋ง ์ ํํ๋ ๊ฒ์ด๋ค.
Type๊ณผ ๋ฌ๋ฆฌ Interface๋ Declaration Merging์ ์ฌ์ฉํ์ฌ ๋ฏธ๋์ ์ฌ์ฉ์๊ฐ ํ์ฅํ ์ ์๋ค. ํ์ฌ Type์ด ๊ฐ์ง ์๋ Interface์ ํน์ฑ์ด๋ค. ๋ชจ๋์ด๋ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ๋ง๋ค ๋ ๋ฏธ๋์ ์ฌ์ฉ์๊ฐ ํ์ฅํ์ฌ ์ฌ์ฉํ Type๋ง Interface๋ก๋ง ์ ์ธํ๋ค.
๋ผ์ด๋ธ๋ฌ๋ฆฌ ๊ฐ๋ฐ์๋ ๊ฐ๋ฐ ์์ ์ ๋ชจ๋ ๊ฐ๋ฅ์ฑ์ ๋ํด ๊ณ ๋ คํ ํ์๊ฐ ์๋ค. ๋ผ์ด๋ธ๋ฌ๋ฆฌ ์ฌ์ฉ์๋ ์ฌ์ฉ ์์ ์ ๋ชจ๋ ๊ฐ๋ฅ์ฑ์ ๋ํด ๊ณ ๋ คํ ์ ์๋ค.
์์๋ก๋ emotion์ Theme ๊ธฐ๋ฅ์ด ์๋ค. emotion์ Theme Interface๋ฅผ ์ฌ์ฉ์๊ฐ ํ์ฅํ ์ ์๋๋ก ์ ๊ณตํ๋ค. ์ฌ์ฉ์๋ ํ์ฅ์ ์ ์ธํ๋ ํ์ผ์ด ์๋ ์ปดํฌ๋ํธ ํ์ผ ๋ฑ์์๋ ๋จ์ํ emotion์ Theme์ importํ์ฌ TypeScript์ ์ฅ์ ์ ํ์ฉํ ์ ์๋ค.
'Dev' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
| WebRTC ์๋ฆฌ ์ฌ์ด ์ค๋ช (0) | 2023.04.24 |
|---|---|
| 2023๋ 1๋ถ๊ธฐ ํ๊ณ (0) | 2023.04.06 |
| React + MVVM (0) | 2023.01.11 |
| Implementing Async/Await From Scratch (0) | 2022.11.29 |
| Async๋ ์ด๋ป๊ฒ ๊ธฐ๋ค๋ ค์ง๋ ๊ฑธ๊น? (1) | 2022.11.29 |