Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save davidystephenson/d1df950b9205b60b8e19019d67c9daef to your computer and use it in GitHub Desktop.

Select an option

Save davidystephenson/d1df950b9205b60b8e19019d67c9daef to your computer and use it in GitHub Desktop.
interface Van <Cargo> {
destination: string
cargo: Cargo
}
const bakeryVan = {
destination: 'bakery',
cargo: 5
}
const schoolVan = {
destination: 'school',
cargo: ['Dorothy', 'Zelda', 'Tallulah']
}
function deliver <Cargo> (van: Van<Cargo>) {
console.log('Delivery arrived at', van.destination)
return van.cargo
}
function receiveBags (bags: number) {
console.log(bags, 'bags received')
}
function receivePassengers (passengers: string[]) {
const joined = passengers.join(', ')
console.log('Passengers received:', joined)
}
const bakeryDelivery = deliver(bakeryVan)
receiveBags(bakeryDelivery)
const schoolDelivery = deliver(schoolVan)
receivePassengers(schoolDelivery)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment