TV has optical and analog audio outputs. Soundbar has both optical and aux analog inputs.
You can use either one. The optical might sound better.
Check the TV manual on how to use the output you chose. The optical may need to be turned on, the TV speakers turned off, and the audio type changed.