Created
August 9, 2025 15:30
-
-
Save davidystephenson/bfcd804527fcff1bf7ece0d914694864 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 Person { | |
name: string | |
age: number | |
email: string | |
phone: string | |
} | |
interface SpecialPerson extends Person { | |
reason: string | |
} | |
const tallulah: SpecialPerson = { | |
name: 'Tallullah', | |
age: 65, | |
email: '[email protected]', | |
phone: '555-555-5555', | |
reason: 'Famous actress' | |
} | |
console.log(tallulah) | |
const david = { | |
name: 'David Y. Stephenson', | |
age: 34, | |
email: '[email protected]', | |
phone: '555-555-5555' | |
} | |
let vipCount = 0 | |
class Guest implements Person { | |
public name: string | |
public age: number | |
email: string | |
phone: string | |
invited: boolean | |
vip: boolean | |
constructor (name: string, age: number, invited: boolean, email: string, phone: string) { | |
this.name = name | |
this.age = age | |
this.invited = invited | |
this.vip = false | |
this.email = email | |
this.phone = phone | |
} | |
makeVip () { | |
this.vip = true | |
vipCount += 1 | |
} | |
} | |
/* | |
function guestFactory (invited: boolean) { | |
const guest = {} | |
guest.invited = invited | |
return guest | |
} | |
*/ | |
const dorothy = new Guest('Dorothy', 60, true, '[email protected]', '555-555-5555') | |
// dorothy.vip = true | |
function describePerson (person: Person, key: keyof Person) { | |
const value = person[key] | |
console.log('The', key, 'of this person is', value) | |
} | |
describePerson(david, 'email') | |
describePerson(dorothy, 'email') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment