Parents should not be critical or judgmental of their children's "imaginary friends," as this can stifle their creativity, which in turn may have an impact on their intelligence, performance in school, and ability to solve problems.
Only if the "friend" becomes a substitute for interaction with real people is there a problem.
Another possibility to consider before dismissing a child's conversations or interactions as an "imaginary friend," is that young children have no preconceived notions or built-in "taboos," and they are much more open, and that "friend" may well be a spirit visitor that the child can see and speak with, but adults, closed-off as many have become, do not.
Some adults retain this sensitivity to those who have passed on--they are the lucky ones who were not ridiculed and "taught" that they were speaking with their own imaginations.
Before you judge or worse, condemn, be open. Ask the child questions about the friend. What are they saying? What do they look like? Then look up the history of the residence. You may find that you have a former occupant still with you.
A ghost or spirit is not necessarily a bad thing; it only seems so, thanks to Hollywood over-dramatizing things for the sake of ratings. In point of fact, there is nothing inherently 'bad' or 'evil' about a spirit. They are merely people who are no longer part of the physical plane, and they retain the personalities they had while here.
There are many reasons and theories why they may not have fully 'crossed over,' and are merely seeking to be noticed, and happy when someone does.
In fact, we have a spirit in our house; it is a somewhat mischievous little girl. The cats can see/sense when she is around, and we've had a few odd things happen, but we are not uncomfortable with our guest.
The bottom line? Never rely on TV shows to guide your real-life actions and decisions.