Platform selection is the key.
If you're choosing a pocket gun or a sub-compact gun, 9mm is a more suitable caliber for a gun that size, though some people can handle 40 well in that small of a gun, most people can't.
If you're choosing a mid-size to full-size pistol, .40, even .45auto can be a very suitable caliber.
My M&P40 launches .40S&W and feels like I'm shooting a 9mm.... Fast, easy, soft.
My STI Edge launches .40S&W and feels like I'm shooting a .380auto... Amazing.
My Browning HighPowers in .40S&W are also very nice handling pistols for caliber.
These guns were designed to handle .40S&W caliber with ease.
My G23 Gen 3, on the other hand, does not handle .40S&W nearly as comfortably (for me), thus I prefer 9mm in that particular platform and would choose a G19 over a G23.
If it was all about fast, easy, effortless shooting, we'd all be rushing to .25autos. If it was all about bullet weight and terminal ballistics, we'd all be shooting .44mag, .45auto, etc.
Pick the platform size that is suitable to your needs and then the caliber you prefer. 9, 40, 45 are all excellent calibers, depending on the particular platform you choose.
The current craze is for very small pistols. Sales of pocket guns are far outstripping sales of mid- and full-size pistols, therefore, 9mm sales are booming as well.
.40S&W is not dying. It will never be as big a seller as 9mm is, but so what? .45auto is nowhere as hot as 9mm is either. .40S&W is a great, soft-shooting, excellent caliber if you have the right platform for it. Same with .45auto. And the terminal ballistics are still better than 9mm.