Created
August 9, 2025 15:00
-
-
Save davidystephenson/f9aeb4a69b7b0fe7ea6c519663f9fb6c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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