๐Ÿ’™ Type Challenges/type-challenges

[TS] type-challenges : 7. Readonly

์„ ๋‹ฌ 2023. 6. 28. 23:32
๋ฐ˜์‘ํ˜•

๋ฌธ์ œ

T์˜ ๋ชจ๋“  ํ”„๋กœํผํ‹ฐ๋ฅผ ์ฝ๊ธฐ ์ „์šฉ(์žฌํ• ๋‹น ๋ถˆ๊ฐ€)์œผ๋กœ ๋ฐ”๊พธ๋Š” ๋‚ด์žฅ ์ œ๋„ค๋ฆญ Readonly<T>๋ฅผ ์ด๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ์•Š๊ณ  ๊ตฌํ˜„ํ•˜์„ธ์š”.

 

์˜ˆ์‹œ:

  interface Todo {
    title: string
    description: string
  }

  const todo: MyReadonly<Todo> = {
    title: "Hey",
    description: "foobar"
  }

  todo.title = "Hello" // Error: cannot reassign a readonly property
  todo.description = "barFoo" // Error: cannot reassign a readonly property

 

ํ’€์ด

type MyReadonly<T> = {readonly [key in keyof T]: T[key]}

 

 

์ถœ์ฒ˜

https://github.com/type-challenges/type-challenges/blob/main/questions/00007-easy-readonly/README.ko.md

 

GitHub - type-challenges/type-challenges: Collection of TypeScript type challenges with online judge

Collection of TypeScript type challenges with online judge - GitHub - type-challenges/type-challenges: Collection of TypeScript type challenges with online judge

github.com

 

 

๋ฐ˜์‘ํ˜•

'๐Ÿ’™ Type Challenges > type-challenges' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

[TS] type-challenges: 18. Length of Tuple  (0) 2023.07.05
[TS] type-challenges: 14. First of Array  (0) 2023.07.04
[TS] type-challenges : 11. Tuple to Object  (0) 2023.07.03
[TS] type-challenges : 4. Pick  (0) 2023.06.28
[TS] type-challenges : 13. Hello World  (0) 2023.06.28