Skip to content

Instantly share code, notes, and snippets.

@susanahernandezd
Created July 20, 2022 04:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save susanahernandezd/b45049465c212c404b2a5e7fa50d0e13 to your computer and use it in GitHub Desktop.
Save susanahernandezd/b45049465c212c404b2a5e7fa50d0e13 to your computer and use it in GitHub Desktop.
//--CASE 1
const person = {
name: 'Tom',
age: 30,
country: 'Chile',
};
// 👇️ type Keys = "name" | "age" | "country"
type Keys = keyof typeof person;
// 👇️ type Values = string | number
type Values = typeof person[Keys];
//--CASE 2
type Person = {
name: string;
age: number;
country: string;
};
// 👇️ type Keys = "name" | "age" | "country"
type Keys = keyof Person;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment