If your soundbar and TV both support HDMI ARC/eARC and Optical connections, the better option is HDMI. Even in its most barebones implementation, HDMI ARC provides the same audio format support as Optical and allows for bidirectional audio signaling.
If you're not familiar with HDMI or ARC/eARC and want to learn more, check out our articles on:
Background
Before the market dominance of Smart TVs, displays functioned primarily as video output devices. Basic setups involved connecting input devices such as satellite receivers, consoles, and video players to an AVR (audio/video receiver), which handled sound and passed a video signal to the TV. However, the increased adoption of Smart TVs loaded with apps like Netflix, coupled with the migration away from AVRs to soundbars, has led TVs to serve a dual purpose as audio output devices. After all, who wants to listen to a Netflix show on TV speakers?
HDMI vs. Optical: What's Best?
The traditional solution to this TV audio problem is to connect an additional cable (often Optical/TOSLINK) to the desired audio device. However, before internet-capable TVs took hold of the mainstream, HDMI 1.4 introduced the game-changing feature, ARC (Audio Return Channel), which allows users to pass audio in both directions across an HDMI connection, eliminating the need for the extra cable from the TV.

While ARC and its updated version, eARC (Enhanced Audio Return Channel), come with extra functionality like shared device controls, their basic ability to transfer audio matches or exceeds the capabilities offered by Optical. Audio quality and format support between HDMI ARC and Optical are the same, while HDMI eARC blows both out of the water with its massively expanded audio bandwidth and format support.

Although HDMI ARC/eARC is better than Optical/TOSLINK for connecting your TV to your soundbar or AVR, it won't work if either device doesn't support the feature, so be sure to check the label on both devices' ports.

Conclusion
As long as your TV and soundbar support ARC/eARC, it's better to connect them with HDMI than Optical. At minimum, HDMI matches the audio quality and format support of Optical while also allowing you to flexibly configure your setup. You can also check out our soundbar setup guide if you need a bit more help.
If you have any questions, feel free to drop a comment below or reach out to us via email.