Skip to content

Latest commit

 

History

History
25 lines (17 loc) · 2.56 KB

File metadata and controls

25 lines (17 loc) · 2.56 KB

Readonly easy #built-in #readonly #object-keys

by Anthony Fu @antfu

Take the Challenge    简体中文 日本語 한국어

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

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

Back Share your Solutions Check out Solutions

Related Challenges

8・Readonly 2 9・Deep Readonly