Last active
May 20, 2019 19:58
-
-
Save JimRottinger/0a07570a895b82fcf86e37b8d1a6fcc5 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
class Car { | |
label: string = 'Generic Car' | |
numWheels: Number = 4 | |
horn() { | |
return "beep beep!" | |
} | |
} | |
class Truck extends Car { | |
label = 'Truck' | |
numWheels = 18 | |
} | |
class Vespa extends Car { | |
label = 'Vespa' | |
numWheels = 2 | |
} | |
function washCar <T extends Car> (car: T) : T { | |
console.log(`Received a ${car.label} in the car wash.`) | |
console.log(`Cleaning all ${car.numWheels} tires.`) | |
console.log('Beeping horn -', car.horn()) | |
console.log('Returning your car now') | |
return car | |
} | |
const myVespa = new Vespa() | |
washCar<Vespa>(myVespa) | |
const myTruck = new Truck() | |
washCar<Truck>(myTruck) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment