HomeAbout

Record

Record Type

Use Record<> for object typing

// key of string and value of string const encode_definitions: Record<string, string> = { "black": "0", "brown": "1", "red": "2", "orange": "3", "yellow": "4", "green": "5", "blue": "6", "violet": "7", "grey": "8", "white": "9" }; // key of string and any value (more common) const some_definitions: Record<string, any> = { "key_one": { "some value" }, "key_two": 2, "key_three": "some other value", }; // using another type as keys options type Choices = 'cat' | 'dog' | 'lizard'; type Pets = Record<Choices, number>; const petPrices: Pets = { cat: 4.41, dog: 8.63, lizard: 13.29, };
AboutContact