"Write what you know."
Boy, that's getting to be the old chestnut of writing advice. It's also hugely misleading. The kernel of truth in it is that whatever you writing should have authenticity. Don't let people catch you out in ignorance. It trips up the reader when they totally figure out that the author has no idea what they are talking about.
This advice is not about, however, only writing from personal experience. If we all did that the fictional landscape would be one helluva a boring place. The whole point of fiction is to take you someplace you don't know. At least it is for me and probably the majority of readers. Very few people pick up a book to escape into a reality so like theirs it is indistinguishable. What they want to do is be able to relate to the characters in the book, but not meet any old regular joe. They want to go to the far reaches of the galaxy, or to ride the Pacific Union Railroad with Butch Cassidy and the Sundance Kid waiting for them around the bend to blow up the safe.
Even if you're reading something that is contemporary you want to peek into the mind and heart, or maybe the madness, of someone you don't know. You might be able to relate, but you aren't them, and they aren't exactly anyone you know either.
The real key to writing what you know is to research and make sure you get the details right, even if it is pure and utter fantasy, and then inject your personal experience into the story to render it authentic. You might not have been born in the 1900s but you can relate to something so tight fitting it makes it hard to breathe, you understand what riding a train is like, and you know the fear that the threat of violence brings.
Every character should be a little bit of an autobiography because you're reaching inside yourself to imagine something completely, but that doesn't mean you know what's like to be a serial killer, or vampire, or a space cowboy 400 light years from home. Every character is also a little bit of biography because you're grabbing stuff from people you know. Even the most ordinary friend has a bit of the extraordinary you can pilfer to bring your characters to life.
Always authenticity is key, so really the old chestnut should read: "write from the heart, and then even what you don't know will come to life for your readers".