This advice, while well meaning, always seemed limiting to me. While it may be easier to write about things and people which you are familiar with, it can be a little restricting to a well developed and diverse story.
There is a quote from 'The Importance of Being Earnest' by Oscar Wilde, "I have always been of opinion that a man who desires to get married should know either everything or nothing. Which do you know?" If you substitute "get married" with "write fiction" I can clearly state that I do not know everything.
However, I cannot agree with Lady Bracknell's following statement, "Ignorance is like a delicate exotic fruit: touch it and the bloom is gone." Ignorance is not bliss. It is the fuel for intolerance and indifference. The notion that we as writers would deny ourselves the chance to expand our outlook and broaden our writing, with characteristics and cultures outside our own, is stifling.
From the perspective of a writer, it can be difficult to know how to best handle the depiction of characters who differ from ourselves in gender, ethnicity, nationality, sexuality, and physicality. Yet, if we are to write developed and realistic characters, diversity is crucial. If the extent of diversity in your writing is hair colour and who has the dreamier eyes, there is definitely a problem.
It is an unfortunate fact that a character will often be presumed to be cisgender, heterosexual and white, unless stated otherwise. Then there is the epidemic of edible characters, where people of colour are labeled with descriptors such as chocolate, cocoa, coffee, caramel, olive, honey, and nut brown. While this might seem like a flattering alternative to stating "she had dark skin" it is more than a little dehumanising, especially when white characters are described as pale, porcelain or tan.
A worry writer's face is that, not only will they misrepresent characters who differ from themselves, but that they will be scrutinised for their choices. Why did they choose to make certain characters bisexual, transgender, or Chinese American? What right do they have to represent these characters? Many writers feel that they can't even lend credibility to the voice and mindset of a protagonist if the character's gender differs from their own. We are ultimately penned in by our insecurities, and these fears keep us from diversifying our writing.
There will always be the chance that you will disappoint or offend readers with poor character and story portrayals. While one quality does not define a character, each one is significant, and there are definite tropes and stereotypes that will discredit your writing and enrage readers. It is a terrifying prospect for a writer. Even so, there is little to be gained from shying away from writing characters unlike yourself. If I wanted to write about myself, I would write a memoir. Then my recollections would clash with those of other people involved and I'd probably get disowned and sued for libel.
I know I need to write more diversely. It's too easy to let fears get in the way of expanding beyond my own familiarity. We read to explore new worlds with engaging, yet initially unfamiliar, characters. We should write for the same reasons.
Don't write what you know. Write what impassions you. Be passionate about diversity, and do your best to represent diverse characters in your writing. Reality doesn't exist inside of a bubble and neither should fiction.