Brandon Watson has an excellent post on Darwin and teleology:
The most important is that the word ‘teleology’ is ambiguous, and was already ambiguous in Darwin’s time. By ‘teleology’ you can mean Paleyan teleology, in which organisms exhibit a design plan that is explained by the imposition of a designer in a special creation at some point in history. There is no question that Darwin rejects this, and rejects it vehemently. The Origin is in many ways one continual attack on this view.
But ‘teleology’ has another meaning, and certainly another meaning in Darwin’s time. It helps if we go back to Georges Cuvier, the zoologist. Cuvier formulated an approach to zoology based on what he called conditions of existence. As he puts it in his work, The Animal Kingdom:
There is, however, a principle peculiar to Natural History, which it uses with advantage on many occasions; it is that of the conditions of existence, commonly styled final causes. As nothing can exist without the re-union of those conditions which render its existence possible, the component parts of each being must be so arranged as to render possible the whole being, not only with regard to itself but to its surrounding relations. The analysis of these conditions frequently conducts us to general laws, as certain as those that are derived from calculation or experiment.
In other words, from the existence of a thing you can infer, in a general way, the conditions that make its existence possible; in particular, the parts of an animal must act and interact in such a way that the animal can actually exist. As we study how action and interactions make the existence of particular animals possible, however, we begin to see general principles governing these conditions of existence, and this is how we understand both how animals work and how they fit into their environment.
The confusion is to equate "design" with an engineer at a drafting table selecting design elements and specifications. This was a reading that came in with the scientific/ engineering revolution.
The telos always was the final cause, that "for which" something acts. Without telos causation becomes incoherent. How can A->B "always or for the most part" unless there is something "in A" that is directed toward B. Otherwise, A might lead to C or D or Z or nothing at all. A heart is "for" circulating the blood in a way it is not for wearing out the artery walls. IOW – as you say – for whole of which it is a part.
Then, too, when Darwin rejected what he thought was "teleology" he was confusing general causes and particular effects. The telos of evolution is quite simple: it tends "always or for the most part" toward greater fitness for a particular niche. This is not necessarily any particular trait or feature. At the highest level, evolution tends toward a diversity of species (as ordained, so to speak, in Genesis).
To speak of the evolution of a particular feature, we shouldn't ask what is the end of evolution, but what is the end of evolution of this species starting out with these features and subsisting in that environment.