Typescript Record utility

Record

Constructs an object type whose property keys are Keys and whose property values are Type. This utility can be used to map the properties of a type to another type.

Example
interface CatInfo {
age: number;
breed: string;
}

type CatName …


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

Record

Constructs an object type whose property keys are Keys and whose property values are Type. This utility can be used to map the properties of a type to another type.

Example
interface CatInfo {
  age: number;
  breed: string;
}

type CatName = "miffy" | "boris" | "mordred";

const cats: Record<CatName, CatInfo> = {
  miffy: { age: 10, breed: "Persian" },
  boris: { age: 5, breed: "Maine Coon" },
  mordred: { age: 16, breed: "British Shorthair" },
};

cats.boris;

const cats: Record<CatName, CatInfo>

Released:
typescript 2.1

reference :Typescript offical documentation.


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


Print Share Comment Cite Upload Translate Updates
APA

es404020 | Sciencx (2021-09-05T13:59:48+00:00) Typescript Record utility. Retrieved from https://www.scien.cx/2021/09/05/typescript-record-utility/

MLA
" » Typescript Record utility." es404020 | Sciencx - Sunday September 5, 2021, https://www.scien.cx/2021/09/05/typescript-record-utility/
HARVARD
es404020 | Sciencx Sunday September 5, 2021 » Typescript Record utility., viewed ,<https://www.scien.cx/2021/09/05/typescript-record-utility/>
VANCOUVER
es404020 | Sciencx - » Typescript Record utility. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/09/05/typescript-record-utility/
CHICAGO
" » Typescript Record utility." es404020 | Sciencx - Accessed . https://www.scien.cx/2021/09/05/typescript-record-utility/
IEEE
" » Typescript Record utility." es404020 | Sciencx [Online]. Available: https://www.scien.cx/2021/09/05/typescript-record-utility/. [Accessed: ]
rf:citation
» Typescript Record utility | es404020 | Sciencx | https://www.scien.cx/2021/09/05/typescript-record-utility/ |

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.