I heard the Messenger of Allah ﷺ say, "Let none of you die except while holding a good opinion of Allah."
حدثنا محمد بن طريف حدثنا أبو معاوية عن الأعمش عن أبي سفيان
سمعت رسول الله ﷺ يقول لا يموتن أحد منكم إلا وهو يحسن الظن بالله
Narrated by Muslim, in the Book of Paradise and Its Bliss, Chapter on the Command to Have Good Expectations of Allah at the Time of Death, hadith no. 81/2877, from the hadith of Abu Muawiya, with this wording.