There are few, if any, interchangeable lenses that give the highest resolution when used wide open or when fully stopped fully, but that doesn't mean you shouldn't use those apertures.
Let's look at the examples of each.
A wide-open aperture, such as f/1.8 or f/2.8, will minimize depth of field, blur backgrounds and give slightly softer images that can be ideal for portraiture.
On the other hand, small apertures such as f/16 or f/22 increase depth of field, often desirable for macro work. It also is useful for scenics and street shooting, where points of interest may be found at several distances, and a deep focus field is essential so everything is sharp.
However if sharpness is your primary goal, a mid aperture, maybe two stops down from wide open, is likely to be your best bet.