The people who say don’t charge overnight are wrong. Charging overnight with Optimized Charging on stops charging at 80%, it then powers the phone from the external source for the rest of the night, allowing the battery to idle with no drain. This reduces the number of times you have to charge the battery, and the capacity of the battery decreases with the number of times you charge it. It then resumes charging to reach 100% just in time for your use in the morning. And the charger, which is actually inside the phone, will never overcharge; it stops charging at 100% also.
There is confusion about 100%; the advice, which people misinterpret, is don’t leave a Lithium ion battery at 100% for long periods of time. In other words, don’t charge it to 100%, then turn off the phone completely. Apple recommends charging to 50% if you plan to store the phone unused, and when you receive a new phone from Apple its charge will be around 50%, so they take their own advice. But if you are using the phone every day it won’t stay at 100% for long. In other applications, such as Teslas, the company says normally don’t charge to more than 80% routinely; there is actually setting for this. But DO charge to 100% before a long drive.
There’s yet another benefit to charging overnight; you can turn on automatic backups, and you will have a fresh backup every morning in iCloud. So the only data loss risk is new content in the current day.