Retrieve a GameObject that has a component that is a subclass of a particular class?

For example, I have a base class for a component called Ship, and a subclass called BigShip.

My current situation is I have a player that has a void OnTriggerEnter (Collider other) entering a ship. This player needs to have access to the ship component that exists in other.

The best way I can think of getting the component is to iterate over all of the components and (somehow) individually check if each Component is a subclass of Ship.

What’s the best way of doing this?

After some trial and error, it turned out to be easy. Basically call GetComponent on the base class. It seems to match anything that is subclassed from that Type automatically.