Skip to content

Latest commit

 

History

History

00007-easy-readonly

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

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