The Imams have clarified that only Allah (swt) has 'ilm al-ghayb, but when they wish to know something, Allah (swt) makes it known to them, and then it is no longer classified as 'ilm al-ghayb.
In Nahj al-Balāgha, Imam ‘Alī (as) defines 'ilm al-ghayb by beginning with a prediction of the coming of the Mongol invasion of the Muslim world:
‘I can see a people whose faces are like shields covered with rough-scraped skins. They dress themselves in silken and woollen clothes and hold dear excellent horses. Their killing and bloodshed shall take place freely til the wounded shall walk over the dead and the number of runners-away shall be less than those taken prisoner.’ One of his companions said to him, ‘O Amir al-Mu’minīn, you have been given knowledge of hidden things.’ Whereupon Amir al-Mu’minīn laughed and said to the man who belonged to the tribe of Bani Kalb: ‘O brother of Kalb! This is not knowledge of hidden things (‘ilm al-ghayb). These matters have been acquired from him (namely the Prophet) who knew them. As regards knowledge of hidden things, that means knowledge of the Day of Judgment, and matters touched upon by Allah in the verse, ‘Verily, Allah is He with Whom is knowledge of the Hour’ (31:34). Therefore, Allah alone knows what is there in the wombs, whether male or female, ugly or handsome, generous or miserly, mischievous or pious, and who will be fuel for Hell and who will be in the company of the Prophets in Paradise. This is the knowledge of hidden things, which is not known by anybody except Allah. All else is that whose knowledge Allah passed on to his Prophet and he passed it on to me, and prayed for me that my chest may retain it and my ribs may hold it.’ (Sermon 127, p. 304).
This is confirmed by the verse in the Qur’an: ‘(He alone is) the Knower of the Unseen, neither does he reveal His secrets unto any (one else) save unto one of the Messengers that He chooses.’ (72:26-27)