Both ways are fine, some people like to specialise and others like to be generalists. But ultimately T-shaped skillsets are the most common in reality - most people know a little about a lot, but have an area where they are most effective (and enjoy working the most). Plus no matter what you should have some level of understanding about what everyone around you is doing.
Remember there's a big difference between knowing something well enough to do it; and knowing it well enough to work well with people who do it.