The following will be mostly useful for software engineers and the likes as the examples used are taken from their sector. Yet, the general ideas are still applicable in other domains.
The first strategy is about becoming an expert in one specific topic, technology or layer that you are already working with or on.
The second strategy is about becoming a good "jack of all trades" with one or a few specific topics or technologies anchoring that.
You don't really have to pick one of the two for ever, you can definitely select one for a time and then switch to the other. Actually that's a bit of my point here.
We usually start our career in one field, centered in one technology such as one programming language. So, the first strategy to follow in such early time is to dig deep into that field. In the case of a programming language and possibly a framework there is plenty of work to do to get a good and deep understanding of them.
That does not mean to stick to one company. You can totally move every few years from one company to another. This will also help see the language and its ecosystem through different lenses.
During this time it's also great to talk to other developers using the same technology with or without more years of experience than you. Talking with peers and possibly doing code katas with them will help you see the language in different ways and learn plenty.
As time goes by, naturally, you should come in contact with other ecosystems, other languages for example. That's when you will have to ask yourself if you want to go deeper in what you already know or if you want to broaden your set of skills.
The approach I would recommend, at least for a time, is to widen your net of interests. As software engineers there are many ways to do that. If you are a writing backend software for APIs you might want to go work on frontend software. You also turn towards devops and cloud operations. You could turn to Machine Learning or Data Science.
At this point, it doesn't matter. You can do that on your own time or get a job as a junior in that field or ask your current team to let you work with another team for a while.
The idea is to get to see something else, to see other problems or the same ones through a different lens and angle. And you should do that until you have good understanding of that new topic or technology.
As a software engineer working on internet based products I often advise people focused on backend engineering to either go dip their tows in the frontend side or the infrastructure one. Although I have a personal preference for the latter I see an interest in both. And, you might actually want to checkout both, get a basic understanding and proficiency in both before digging deeper in one.
The point, in the end
The point is to become either a very specialized expert in one field or be a good expert in one field and a good professional in several fields related to it.
So, in other terms : become a I shaped individual (specialized in one) or a T shaped individual (with a great knowledge of one topic but also a good knowledge in multiple topics connected to it).
As a team lead and recruiter at times both profiles will land high on my shortlist but the T shaped individuals are the ones I am most looking for. Those are the ones able to lead a team by acting at different levels, spearheading initiatives but also second other engineers in their tasks or interact well with them because of the common vocabulary and perspectives.
Over the last 10 years, the people that I have had delight working with were on both side of that spectrum. And it's really up to each one of us to figure out what we prefer to do. Yet remember it's not set in stone and you can always change direction after some time.
The important part is to find something you like and want to do for a while. Software engineering is one of those rare careers where you have plenty of opportunities to make that happen. The rest is secondary.
Find good peers (such as mentors) to help you along that choice or, at least, with whom you can bounce ideas and consider your options.