questions/00008-medium-readonly-2/README.ja.md
2つの型引数TとKを取るMyReadonly2<T, K>を実装します。
Kが指定されている場合は、Tの中のKのプロパティのみを読み取り専用にします。Kが指定されていない場合は、通常のReadonly<T>と同様に、すべてのプロパティを読み取り専用にします。
例えば
interface Todo {
title: string
description: string
completed: boolean
}
const todo: MyReadonly2<Todo, 'title' | 'description'> = {
title: "Hey",
description: "foobar",
completed: false,
}
todo.title = "Hello" // Error: cannot reassign a readonly property
todo.description = "barFoo" // Error: cannot reassign a readonly property
todo.completed = true // OK
<a href="../../README.ja.md" target="_blank"></a> <a href="https://tsch.js.org/8/answer/ja" target="_blank"></a> <a href="https://tsch.js.org/8/solutions" target="_blank"></a> <hr><h3>関連する課題</h3><a href="https://github.com/type-challenges/type-challenges/blob/main/questions/00007-easy-readonly/README.ja.md" target="_blank"></a> <a href="https://github.com/type-challenges/type-challenges/blob/main/questions/00009-medium-deep-readonly/README.ja.md" target="_blank"></a> <!--info-footer-end-->