Refine object unions by checking for a property that only one variant has. Use 'pages' in x vs 'duration' in x to decide how to read the value. Reduce the array to a single number for easy comparison.
function metric(x: { pages: number } | { duration: number }) {
return "pages" in x ? x.pages : x.duration;
}
Sum the metric across the whole list.
Sum pages for books and minutes for movies.