First-time fiction writers are often told to “write what you know.” This well-meant advice assumes that inexperienced writers will have an easier time expressing themselves if the subject of a fictional creation is familiar. That is generally true, but some new writers may misinterpret the suggestion and conclude that they should write only about events they have personally experienced. Such a restriction is not beneficial to the creative process.
If you want to write speculative fiction (e.g., the science fiction, fantasy, and horror genres), the world you create will be imaginary, so how can you “write what you know”? In this case, the advice applies to internal, rather than external, elements of the story. The externals—setting, time, atmosphere, plot, and so on—can be highly imaginary. But the internals—primarily character and motivation—will be based on your own experiences.
For instance, if you are writing about the inhabitants of an alien civilization, you will probably consider in what ways they are like humans, and in what ways they are different. Since you are (presumably) human yourself, your interpretation will be based on what you know about human nature, including what you have observed in others. If you’re writing about a robot or computer that incorporates artificial intelligence, you will have to decide which, if any, human characteristics are evident in its technology, how these characteristics are manifested, and why they were (or were not) included by the technology’s designers. Your imagination is the driver of your story, but the directions your imagination takes grow from your own life experiences.
So yes, write what you know, but don’t take that advice too literally. If you want to write speculative fiction, do it. You will inevitably include parts of your own experience in the story.