Complete worked example
typescript
type Animal = { name: string };
type Dog = Animal & { bark(): void };
function visit(animal: Animal, describe: (value: Animal) => string): string { return describe(animal); }
const description = visit({name:"Milo"}, value => value.name);- Reasoning
- A callback accepting every Animal can safely handle the value the consumer supplies.