Is there a way to define a type by the values of a field in an array?
To simplify my question... Given that I have a static array:
const arr = [
{name: 'cat', language: 'meow'},
{name: 'dog', language: 'bark'},
{name: 'cow', language: 'moo'}
]
And I want to be able to create a function that gets the language based on the name field defined like so
function getLanguage(name: X) {
What can I define the type X to be so that I can limit X (the parameter of that function) to be any of the name fields in that list of objects?