View on GitHub: https://tsch.js.org/7
*/
/* _____________ Your Code Here _____________ */
type MyReadonly View on GitHub: https://tsch.js.org/7
*/ /* _____________ Your Code Here _____________ */ type MyReadonly<T> = any /* _____________ Test Cases _____________ */
import { Equal, Expect } from '@type-challenges/utils' type cases = [
Expect<Equal<MyReadonly<Todo1>, Readonly<Todo1>>>,
] interface Todo1 {
title: string
description: string
completed: boolean
} /* _____________ Further Steps _____________ /
/ Share your solutions: https://tsch.js.org/7/answer
View solutions: https://tsch.js.org/7/solutions
More Challenges: https://tsch.js.org
*//*
7 - Readonly<T>
-------
by Anthony Fu (@antfu) #easy #built-in #readonly #object-keys
### Question
Implement the built-in `Readonly<T>` generic without using it.
Constructs a type with all properties of T set to readonly, meaning the properties of the constructed type cannot be reassigned.
For example
```ts
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
프로퍼티 들을 Readonly 로 만들자.
```tsx
type MyReadonly<T> = {
readonly [P in keyof T]: T[P]
}