type StringKeys = 'firstName' | 'lastName';
type NumberKeys = 'age';
type Person = {
[Key in StringKeys]: string;
A function that accepts an argument of an anonymous type where hobbies
is a tuple:
function stringifyPerson(person: {
name: string;
age: number;
hobbies: [string, string]; // tuple
}) {
return `${person.name} is ${person.age} years old and loves ${person.hobbies.join(" and ")}.`;
OlderNewer