There's two sides to this argument (coming from a commercial standpoint):
SHORT-TERM ANSWER: GO THE SIMPLE ROUTE AND WRITE WHAT YOU KNOW
Make as much music as you can and get yourself out there. The more music of yours is out there, the more you'll get heard.
Say you're good at RnB: Maybe someone approaches you who heard your tracks and who wants you to write for him. Katshing!
This is good for making relatively short-term money. You write, people like it, ask you to write for them.
LONG-TERM ANSWER: GO THE DIFFICULT ROUTE AND CONSTANTLY PUSH YOURSELF
At least for the first couple of years in your writing career I suggest writing what you don't know. Try everything.
This adds to your repertoire AND your skill set. Unless you absolutely have to make a living with your music, this is the way
to go if you want long term success, because the only way to get better is to move out of your comfort zone.
I know a lot of writers who if you listened to their music you'd say "amazing". But the crux is: That's literally all they can do.
Ask them to write Hip Hop and they can't do it. They've just learned how to do one thing very well. And again, there's a place
for that. But if you want to achieve long-lasting success, the answer has to be train yourself to become an outstanding writer
with a lot of knowledge.
As an example: I have written for rock bands, jazz trios, big bands, orchestras and drum bands. I have
written all-electronical. I have written interactive pieces. I've written for television, games, radio and commercials. Did I enjoy
every second of it? Hell no. Some of that stuff was very difficult to pull off. But ultimately, it has made me a better writer.
Hope this answers your question. Let me know if all of this triggered some new questions