I have tried to maintain a generalist role[1]. It's worked very well for me so far - and there's some peace of mind in knowing that if needed, you can switch areas reasonably easy. And I harbor the hope that at some point (when kids go to university) I may start my own business, since I've looked for enhancing those skills. It's not without downsides though - you get the occasional impostor syndrome (since you'll never be able have the depth you wish/ know you could achieve, in any area). It's hard to balance being at least "good enough" at the current task with broadening your knowledge, and it can be straining at times. And also, though in theory you can get hired anywhere - in practice, relatively few companies will appreciate you enough to pay you well, since most companies' ideal candidates are really specialists in very narrow fields (also those ideal candidates tend to be unicorns, so companies settle for generalists, but that's a different discussion). The end result of this is that, unless you're willing to take a significant pay cut, the opportunities to switch companies might get increasingly rare (but opportunities to switch roles within company will be present).
[1] I've developed (professionally/ for money) compilers, VMs, image processing, web apps (mostly middleware), desktop apps, "big data"(spark, kafka streams, etc.); Have done product management, data science, and even worked on the architecture of a DSP processor at a time. Worked in most of the "mainstream" languages (Java, Scala, C. C++, Javascript, Python, C#, Vb.net; and of course various kinds of assembly language).
[1] I've developed (professionally/ for money) compilers, VMs, image processing, web apps (mostly middleware), desktop apps, "big data"(spark, kafka streams, etc.); Have done product management, data science, and even worked on the architecture of a DSP processor at a time. Worked in most of the "mainstream" languages (Java, Scala, C. C++, Javascript, Python, C#, Vb.net; and of course various kinds of assembly language).