I don't think there's any evidence that
software sales are affected by hardware announcements, as
@YolkFolk mentioned The Last of Us is a good counter-example. In fact both The Last of Us and The Last Of Us 2 released around a week after Sony's major showcase of next-gen hardware, and both sold very well.
There's more evidence that hardware sales are affected by announcements, but it's difficult to say definitively, because at that point of a console's life you would expect sales to decline anyway. In Nintendo's case at the moment a lot of hardware sales are the OLED model, which might indicate a large number of people upgrading from the original Switch. I don't think people who are looking to buy a Switch for the first time in 2023 would be particularly likely to hold off to buy a Switch 2 on day one in 2024 instead, but I would imagine at least some of those who are upgrading to the OLED model would hold off for the Switch 2 if they knew it was coming. I could certainly see that having an impact on hardware sales.
At the same time, the existence of a new Switch could have the same effect even without an official announcement if details are leaked and widely reported. If the full details and launch window of Switch 2 get leaked and published on every gaming and tech site on the internet, then those enthusiasts who were going to upgrade to an OLED model may still hold off. In that case, there's an argument that Nintendo may want to just make it official and control the narrative.