Hmm. I'm a 60-year-old developer who continues to be very employable.
I never specialized. Many people I know did, and now they're obsolete.
I have worked in fintech (sorry), cryptocurrencies (really sorry), search, big data, digital audio, animation, scientific programming, and hardware, and there are probably a few I missed.
I've switched my main language multiple times: C to Pascal to C to C++ to Java to C++ again to Python.
Bounce or break, baby. "Specialization is for insects." -Robert Heinlein
----
Now I'm going to take the opposite side.
I managed to do this by being somewhat smart, but also, by setting out to be a generalist from a very early age. I have a math degree and 40 years later, I keep most of the material fresh. I can talk intelligently with scientists and with financial traders. I have a kick-ass resume with a lot of interesting looking jobs. I have tried to aim only for the most tricky programming on the theory that difficult problems will always need solving.
I would claim that my path is probably not possible for most, and your suggestion is more practical and reasonable for 90% of the readers.
----
Pick the one you like! :-D