Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save davidystephenson/f9aeb4a69b7b0fe7ea6c519663f9fb6c to your computer and use it in GitHub Desktop.
Save davidystephenson/f9aeb4a69b7b0fe7ea6c519663f9fb6c to your computer and use it in GitHub Desktop.
interface Guest {
name: string
age: number
email: string
phone: string
address: string
}
type GuestKey = keyof Guest // 'name' | 'age' | 'email' | 'phone' | 'address'
const dorothy = {
name: 'Dorothy',
age: 60,
email: '[email protected]',
phone: '555-555-5555',
address: '123 fake street'
}
console.log('dorothy', dorothy)
function describeGuest (guest: Guest, key: GuestKey) {
const value = guest[key]
console.log('The', key, 'for this guest is', value)
}
describeGuest(dorothy, 'age')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment