00005-extreme-readonly-keys
Extreme
utils
object-keys

チャレンジのソース: type-challenges/00005-extreme-readonly-keys

オブジェクトの読み取り専用キーの Union を返す汎用的な GetReadonlyKeys<T> を実装してください。

例えば

interface Todo {
  readonly title: string
  readonly description: string
  completed: boolean
}

type Keys = GetReadonlyKeys<Todo> // expected to be "title" | "description"

Loading...
import type { Equal, Expect } from '@type-challenges/utils'

type cases = [
  Expect<Equal<'title', GetReadonlyKeys<Todo1>>>,
  Expect<Equal<'title' | 'description', GetReadonlyKeys<Todo2>>>,
]

interface Todo1 {
  readonly title: string
  description: string
  completed: boolean
}

interface Todo2 {
  readonly title: string
  readonly description: string
  completed?: boolean
}