Why are intellectual property rights necessary when nothing prevents a company from having trade secrets?
Trade secrets must be kept secret. There are plenty of intellectual properties that can't be kept secret. The most obvious ones would be a writer, musician or composer - the whole reason for their work is to publish it and make it available to as many people as possible. How could that possibly be a trade secret? Similar with trademarks. The whole point of a trademark is to be widely visible.
And there are patents. Here the situation is different. Before patent law, inventors kept their inventions indeed secret. Then people realised that this secrecy is in the way of progress. So patent law was created, which gives an inventor rights beyond those of a trade secret, at the cost of having to publish their invention. Even if you invent today, you have the choice of keeping your invention secret and relying on trade secret law, or patenting it and relying on patent law. Again, some inventions are clearly visible. When the bycicle was invented, it was clearly visible to everyone and couldn't be kept secret.
Intellectual property law includes trade-secret law.
Trade secret laws are designed to protect information that derives value from being kept secret.
The more traditional areas of IP law (copyright, trademark, patent) are generally designed to protect information that derives value from being disclosed.
The central premise of IP law is that whoever comes up with an idea should get guaranteed exclusive rights to benefit from that idea for some time. I don't personally agree with it, but obviously we must accept this to meaningfully discuss IP law.
By trade secrets I suppose you mean that a company can DIY its own IP protection by just not telling anyone how it makes a certain product.
One problem here is that if someone steals the trade secret, this "protection" is irreversibly lost. So IP law protects inventors from IP theft, because the thief or anyone else would still not be able to legally benefit from the stolen IP even if they did steal it. This in turn helps discourage IP theft as well.
The other problem is that it is impossible to keep trade secrets 100% secure. No matter what you do, it is possible for someone to reverse-engineer or copy your product once you do produce it. With things like text (books), audio or video it is trivial to copy and anyone can do it. Furthermore, someone might independently come up with the same idea and destroy your competitive advantage.
Now, if the whole point of IP law is that thinking of an idea should be rewarded with exclusive rights to it, then shouldn't the re-inventor be entitled to the protections also? I think so, but the current system rewards only the first inventor, not reinventors. Arguably, the inventor adds something to the collective knowledge of society, while the reinventor would not, so only the former should be incentivized with the promise of a temporary state sanctioned monopoly.