Back to Type Challenges

README

questions/00005-extreme-readonly-keys/README.md

latest1.9 KB
Original Source
<!--info-header-start--><h1>Get Readonly Keys </h1><blockquote><p>by Anthony Fu <a href="https://github.com/antfu" target="_blank">@antfu</a></p></blockquote><p><a href="https://tsch.js.org/5/play" target="_blank"></a> &nbsp;&nbsp;&nbsp;<a href="./README.zh-CN.md" target="_blank"></a> <a href="./README.ja.md" target="_blank"></a> <a href="./README.ko.md" target="_blank"></a> <a href="./README.pt-BR.md" target="_blank"></a> </p><!--info-header-end-->

Implement a generic GetReadonlyKeys<T> that returns a union of the readonly keys of an Object.

For example

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

type Keys = GetReadonlyKeys<Todo> // expected to be "title" | "description"
<!--info-footer-start-->

<a href="../../README.md" target="_blank"></a> <a href="https://tsch.js.org/5/answer" target="_blank"></a> <a href="https://tsch.js.org/5/solutions" target="_blank"></a> <!--info-footer-end-->