True dreams
We relate to you, [O Muhammad], the best of stories in what We have revealed to you of this Qur'an although you were, before it, among the unaware.
[Of these stories mention] when Joseph said to his father, "O my father, indeed I have seen [in a dream] eleven stars and the sun and the moon; I saw them prostrating to me."
Qur'ān 12:3-4
Imām al-Tabari writes:
قال أبو جعفر: يقول تعالى ذكره لنبيه محمد صلى الله عليه وسلم: وإن كنت يا محمد، لمن الغافلين عن نبأ يوسف بن يعقوب بن إسحاق بن إبراهيم ، إذ قال لأبيه يعقوب بن إسحاق: (يا أبت إني رأيت أحدَ عشر كوكبًا) ; يقول: إني رأيت في منامي أحد عشر كوكبًا .
Allāh says to His Prophet Muhammad sallallaahu alayhi wa sallam And you, O Muhammad, were from among the ghāfilūn (those who were unaware) about the news of Yūsuf bin Ya'qūb bin Ishāq bin Ibrāhīm when he said to his father "O my father, indeed I have seen [in a dream] eleven stars..."
وقيل: إن رؤيا الأنبياء كانت وحيًا .
It has been said that the dreams of the Prophets are revelation
Narrated Abu Huraira:
Allah's Messenger (sallallaahu alayhi wa sallam) said, "The (good) dream of a faithful believer is a part of the forty-six parts of Prophethood."
Sahīh al-Bukhāri Hadīth No. 6988
What does forty-six parts of Prophethood mean?
Ibn Battāl (paraphrase) writes:
The word Prophethood (al-nubuwwa النبوة) comes from the word al-naba' (النبأ) and al-inbā' (الإنباء) which mean الاعلام (to give notification, information). And the meaning is that the true dream is a truthful notification from Allāh in which there is no lies just like the meaning of Prophethood is truthful notification from Allāh which can harbor no lies so a true dream resembles Prophethood in being a truthful notification about the unseen.
Ibn Uthaymīn (paraphrase) said:
وتخصيص الجزء بستة وأربعين جزءاً من الأمور التوقيفية التي لا تُعلم حكمتها كأعداد الركعات والصلوات
As for the specification that a true dream is forty-six parts of Prophethood, then this is a matter the hikmah of which we do not know just like we do not know the hikmah of the number of Rak'ah (of the prayers) or of the number of prayers (in a day). It is a matter which is tauqīfīyah.
Dreams of a believer are of three types
It was narrated from Abu Hurairah that the Prophet (sallallaahu alayhi wa sallam) said:
“Dreams are of three types: Glad tidings from Allah, what is on a person’s mind, and frightening dreams from Satan. If any of you sees a dream that he likes, let him tell others of it if he wishes, but if he sees something that he dislikes, he should not tell anyone about it, and he should get up and perform prayer.”
Sunan Ibn Mājah Hadīth No. 3906
When you see a bad dream do this
Narrated Abu Salama:
I used to see a dream which would make me sick till I heard Abu Qatada saying, "I too, used to see a dream which would make me sick till I heard the Prophet (sallallaahu alayhi wa sallam) saying, "A good dream is from Allah, so if anyone of you saw a dream which he liked, he should not tell it to anybody except to the one whom he loves, and if he saw a dream which he disliked, then he should seek refuge with Allah from its evil and from the evil of Satan, and spit three times (on his left) and should not tell it to anybody, for it will not harm him."
Sahīh al-Bukhāri Hadīth No. 7044
Reference(s):
Tafsīr al-Tabari
Sharh Sahīh al-Bukhāri li Ibn Battāl
Volume 9 Page 517