I'm not yet in the 40+ (being 38 as of today), but don't see myself hitting a dead-end soon. As @JanVladimirMostert mentioned, over the years you'll experience repetition of patterns and trends. The recipe I used to still be valuable and enjoy what I'm doing is trying to avoid the hype-trap and use your experience to bring value to your company for embracing new technologies that are likely to stay useful. In other words, choose wisely where you want to put your focus on, and you'll be able to be relevant and desired.
On the other end, you don't have to wait 40 to notice that our domain is evolving at such a fast pace that as soon as you have 10 years of useful experience, the additional years usually don't matter. (If you focus on a very specific domain, like pure front-end, I guess this could even be true with a smaller time span).
Technical experience you got more than 10 years ago is unlikely to be relevant today, so that's true that you might find that there's much a gap in technical expertise between a 35 years old and a 45 years old engineer. (I mean on average, we all know outstanding 25 years old boys, and older people that doesn't seem to learn anything from all ages ;-)
But technical experience isn't all the story. We work in teams, we have to forecast projects evolution and stuff like that, and that's where older smart people could bring additional value to the team.