It is certainly a lot better than the last similar promise made in the period of the Judges:
30 And Jephthah made a vow to the LORDand said, “If you will give the Ammonites into my hand, 31 then whatever comes out from the doors of my house to meet me when I return in peace from the Ammonites shall be the LORD’s, and I will offer it up for a burnt offering.” 32 So Jephthah crossed over to the Ammonites to fight against them, and the LORD gave them into his hand. 33 And he struck them from Aroer to the neighborhood of Minnith, twenty cities, and as far as Abel-keramim, with a great blow. So the Ammonites were subdued before the people of Israel.
34 Then Jephthah came to his home at Mizpah. And behold, his daughter came out to meet him with tambourines and with dances.
But there is loss involved, as when Samuel is born in answer to this prayer, and because God is faithful, she will only now get to see her child when she visits him at the temple, where he is living with Eli the priest.
I would say that though Hannah's promise is extravagant, it is not foolish. The firstborn, after all, belongs to the LORD (Ex 13:12-13).
And her faithfulness in the face of her husband's other wife's taunts (v 6), her husband's insensitivity (v 8), and Eli's impatient misconstruing of her prayerfulness as drunkenness (v 13) shines out like a beacon in the midst of a dark generation.
This verse is delightful:
Indeed the LORD visited Hannah, and she conceived and bore three sons and two daughters. And the young man Samuel grew in the presence of the LORD.
-1 Sam 2:21