Improve sample code in Avoid type checking

This commit is contained in:
ryo 2020-06-13 17:04:41 +09:00 committed by kawamataryou
parent c70fb6fd8a
commit eb1fe6ef71

View file

@ -971,7 +971,17 @@ function travelToTexas(vehicle: Bicycle | Car) {
**Good:**
```ts
type Vehicle = Bicycle | Car;
interface Vehicle {
move(current: Location, destination: Location): void
}
class Bicycle implements Vehicle {
// ...
}
class Car implements Vehicle {
// ...
}
function travelToTexas(vehicle: Vehicle) {
vehicle.move(currentLocation, new Location('texas'));