Capstone: typed inventory lookup
Everything so far comes together here: an interface for the shape of an
item, a function whose return type is a union (Item | undefined, since a
lookup might not find anything), and a generic helper that works regardless
of what's in the array.
array.find(fn) returns the first item where fn returns true, or
undefined if none match - which is exactly what an Item | undefined
return type promises the caller: check before assuming you got a real item
back.
Your task: define Item with id: number and name: string, write
findItem(items, id) returning the matching item or undefined, and a
generic count(arr) returning arr.length.
You'll practice:
- Combining an interface with a union return type
- Writing a generic helper that works on any array