I heard the Messenger of Allah ﷺ say, "No prophet falls ill except that he is given the choice between this world and the next."During the illness in which he passed away, he developed severe hoarseness, and I heard him say, "With those whom Allah has favored of the prophets, the truthful, the martyrs, and the righteous" [Nisa 4:69]. So I knew that he had been given the choice.
سمعت رسول الله ﷺ يقول: ما من نبي يمرض إلا خير بين الدنيا والآخرة، وكان في شكواه الذي قبض فيه أخذته بحة شديدة، فسمعته يقول: {مع الذين أنعم الله عليهم من النبين والصديقين والشهداء والصلحين} فعلمت أنه خير.
Bukhari narrated it in the tafsir (4586), and Muslim in the virtues of the companions (2444:86), both through Saad bin Ibrahim, from Urwa, from Ayesha, who said, and she mentioned it. The wording given is that of Bukhari, and Muslim's wording is similar.