결론
enum 보다는 union type
이유
컴파일 해보면 객체가 생성됨
> typescript 사용 이유가 정적 타입을 사용하기 위함인데, 정적 타입 정보가 런다음에 영향을 준다는 사실이 썩 내키지 않는다.
> const enum을 사용해도 되지만, import 구문이 추가됨
enum Fruite {
Banana,
Apple,
Orange
}
complied
"use strict";
var Fruite;
(function (Fruite) {
Fruite[Fruite["Banana"] = 0] = "Banana";
Fruite[Fruite["Apple"] = 1] = "Apple";
Fruite[Fruite["Orange"] = 2] = "Orange";
})(Fruite || (Fruite = {}));
대안
union type
type fruit = 'apple' | 'banana' | 'orange'
https://fe-developers.kakaoent.com/
홈 | 카카오엔터테인먼트 FE 기술블로그
fe-developers.kakaoent.com
'IT > typescript' 카테고리의 다른 글
[Typescript] 외부 패키지의 타입 치환 (1) | 2024.02.05 |
---|---|
[Typescript] index signature vs mapped type (0) | 2024.02.05 |
TS - 5.0 New features (0) | 2023.07.01 |
TS - unknown vs any (0) | 2023.06.27 |
TS - never (0) | 2023.06.27 |