๋ฐ์ํ
๋ฌธ์
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]}
์ถ์ฒ
๋ฐ์ํ
'๐ Typescript > 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 |