Back to Type Challenges

README.Pt BR

questions/00008-medium-readonly-2/README.pt-BR.md

latest2.9 KB
Original Source
<!--info-header-start--><h1>Readonly 2 </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/8/play/pt-BR" target="_blank"></a> &nbsp;&nbsp;&nbsp;<a href="./README.md" target="_blank"></a> <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> </p><!--info-header-end-->

Traduzido pelo Google, abra um PR para ajudar a melhorar a tradução.

Implemente um MyReadonly2<T, K> genérico que recebe dois argumentos de tipo T e K.

K especifica o conjunto de propriedades de T que deve ser definido como Somente leitura. Quando K não é fornecido, ele deve tornar todas as propriedades somente leitura, assim como o Readonly<T> normal.

Por exemplo

ts
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
<!--info-footer-start-->

<a href="../../README.pt-BR.md" target="_blank"></a> <a href="https://tsch.js.org/8/answer/pt-BR" target="_blank"></a> <a href="https://tsch.js.org/8/solutions" target="_blank"></a> <hr><h3>Desafios Relacionados</h3><a href="https://github.com/type-challenges/type-challenges/blob/main/questions/00007-easy-readonly/README.pt-BR.md" target="_blank"></a> <a href="https://github.com/type-challenges/type-challenges/blob/main/questions/00009-medium-deep-readonly/README.pt-BR.md" target="_blank"></a> <!--info-footer-end-->