---
type: snippet
tags: ['status', 'ternary']
status: release
ctime: 2024-12-31
mtime: 2024-12-31
---

```ts
const color =
  (isUnchecked && 'palette.label.alternative') ||
  (isChecked && 'palette.primary.normal') ||
  'palette.label.normal'
```

중첩 삼항/논리 연산자는 간결하지만 상태가 늘어나면 유지보수 어려움.

핵심: **`status` 모델을 어떻게 정의하고 참조할 것인가?**

```ts
class StatusManager {
  static Status = {
    UNCHECKED: 'UNCHECKED',
    CHECKED: 'CHECKED',
    DEFAULT: 'DEFAULT',
  } as const

  static getColor(status: keyof typeof this.Status) {
    switch (status) {
      case this.Status.UNCHECKED:
        return 'palette.label.alternative'
      case this.Status.CHECKED:
        return 'palette.primary.normal'
      default:
        return 'palette.label.normal'
    }
  }
}

const color = StatusManager.getColor(StatusManager.Status.CHECKED)
```

---

- [Expression of type string can&#x27;t be used to index type X | Total TypeScript](https://www.totaltypescript.com/concepts/type-string-cannot-be-used-to-index-type)
