You should try doing this if you want to avoid the error and if the testData
is really optional.
const myData = [
...(testData.length > 0 ? testData : []),
{
label: 'first',
value: 'firstValue',
},
...(isVisible ? [{ label: 'second', value: 'secondValue' }] : []),
];