Usul al-Kafi
Book 4:
The Book of Divine Proof

Chapter45
Knowledge of the unseen

389. 2. Humran bin Aayun asked Imam Muhammad al-Baqir (p) to comment on the verse: God is the Originator of the heavens and the earth. (Q, 2:117)
The Imam (p): God, the Mighty, the Glorious brought into existence every thing with the power of His knowledge and without any pre-existing model. He created the heavens and the earth when there were no heavens and earth. Have you not heard the words of God: …His Throne was on waters… (Q, 11:7)?
At this point Humran said: But God says: He (God) alone knows the Unseen and does not make anyone acquainted with His mysteries (Q, 72:26).
The Imam (p) referred to the words immediately following thereafter, which are: Except an apostle whom He has chosen… (Q, 72:27) and said: By God! Prophet Muhammad (p) is one of the chosen ones.
The Imam (p) then added that when God wishes, He sends the knowledge through his Angels to the Apostle, then to us.

390. 4. Imam Jafar as-Sadiq (p) was asked: Does an Imam have the knowledge of the unseen? The Imam (p): No, but when God wishes an Imam (p) to know it, He reveals it.