```typescript
const Color = {
Red: "red", // string
Green: "green", // string
Blue: "blue", // string
}
```
위의 코드에선 Color의 property가 각각 `string`으로 추론이 된다.
---
`Color.Red`나 `Color.Green` 같은 값이 변경되지 않을 때 또는 예상될 때 string이 아닌 특정 [[String literal type|literal]] 로 고정시킬 수 있다.
```typescript
export const Color = {
Red: "red", // "red"
Green: "green", //"green"
Blue: "blue", // "blue"
} as const
```
Object 뒤에 `as const` 를 붙이게 되면 Color의 property를 수정할 수 없고 읽기만 가능한데 주석에도 달아놨지만 더 이상 string으로 추론되는 것이 아니라 [[String literal type]]으로 추론이 된다.
---
그렇다면 이것은 언제 유용할까? 다른 언어에 존재하는 기능인 `enum`처럼 값이 항상 고정된 값을 갖는 case에서 사용할 수 있는데 아래의 예제에서, `color` 함수에서 넘어오는 인자의 타입을 특정 [[String literal type]], "red", "blue", "green" 으로 고정시킬 수 있고 실수로 다른 string을 입력했을 때 에러가 발생한다.
```typescript
type ColorType = keyof typeof Color
function color(c: ColorType){
// do something
}
color(Color.Red)
```
---
참조 강의: https://inf.run/FVDi