TOSLink was kind of a silly idea because digital electrical signals would also prevent ground loops. The key is digital vs. analog, not optical vs. electrical.
Ground loops comes from the ground mismatch between two electrically connected devices. When you use an optical link, you isolate those two devices since there is no common ground and the hum goes away. Same if connect a battery device to a grounded device.