📌 문제
type-challenges/questions/00007-easy-readonly/README.ko.md at main · type-challenges/type-challenges
Collection of TypeScript type challenges with online judge - type-challenges/type-challenges
github.com
✅ 답
type MyReadonly<T> = { readonly [K in keyof T]: T[K] };
T 안의 key를 돌면서 T[k] Readonly로 바꾸기
Readonly<Type>
interface Todo {
title: string;
}
const todo: Readonly<Todo> = {
title: "Delete inactive users",
};
todo.title = "Hello";
Cannot assign to 'title' because it is a read-only property.
Readonly<Type>은 Type에 있는 모든 프로퍼티를 읽기 전용이 되어 이후 해당 프로퍼티의 값을 수정할 수 없게 만든다.
'TypeScript' 카테고리의 다른 글
| Type Challenges :00003-medium-omit (0) | 2025.05.06 |
|---|---|
| 친해지기3-Type Challenges : 00011-easy-tuple-to-object (0) | 2025.04.30 |
| 친해지기1- Type Challenges : 00004-easy-pick (0) | 2025.04.28 |
| [TS] 타입 가드 & 타입 내로잉(is, as const, keyof, typeof, as) (0) | 2025.04.23 |
| [TS] 타입스크립트에서의 클래스 (0) | 2025.04.23 |