Typescript Utility Readonly

Readonly

Constructs a type with all properties of Type set to readonly, meaning the properties of the constructed type cannot be reassigned.

interface Todo {
title: string;
}

const todo: Readonly<Todo> = {
title: “Delete inactive users”…


This content originally appeared on DEV Community and was authored by es404020

Readonly

Constructs a type with all properties of Type set to readonly, meaning the properties of the constructed type cannot be reassigned.


interface Todo {
  title: string;
}

const todo: Readonly<Todo> = {
  title: "Delete inactive users",
};

todo.title = "Hello";

Assigning a title to Todo Interface would throw an error .

Released:2.1

Reference: Official typescript docs


This content originally appeared on DEV Community and was authored by es404020


Print Share Comment Cite Upload Translate Updates
APA

es404020 | Sciencx (2021-09-08T07:17:16+00:00) Typescript Utility Readonly. Retrieved from https://www.scien.cx/2021/09/08/typescript-utility-readonly/

MLA
" » Typescript Utility Readonly." es404020 | Sciencx - Wednesday September 8, 2021, https://www.scien.cx/2021/09/08/typescript-utility-readonly/
HARVARD
es404020 | Sciencx Wednesday September 8, 2021 » Typescript Utility Readonly., viewed ,<https://www.scien.cx/2021/09/08/typescript-utility-readonly/>
VANCOUVER
es404020 | Sciencx - » Typescript Utility Readonly. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/09/08/typescript-utility-readonly/
CHICAGO
" » Typescript Utility Readonly." es404020 | Sciencx - Accessed . https://www.scien.cx/2021/09/08/typescript-utility-readonly/
IEEE
" » Typescript Utility Readonly." es404020 | Sciencx [Online]. Available: https://www.scien.cx/2021/09/08/typescript-utility-readonly/. [Accessed: ]
rf:citation
» Typescript Utility Readonly | es404020 | Sciencx | https://www.scien.cx/2021/09/08/typescript-utility-readonly/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.