mirror of
https://github.com/labs42io/clean-code-typescript.git
synced 2025-04-18 15:13:34 +00:00
Improve sample code in Avoid type checking
This commit is contained in:
parent
c70fb6fd8a
commit
eb1fe6ef71
1 changed files with 11 additions and 1 deletions
12
README.md
12
README.md
|
@ -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'));
|
||||
|
|
Loading…
Add table
Reference in a new issue